From the course: Building a Website with Node.js and Express.js

Unlock the full course today

Join today to access over 24,800 courses taught by industry experts.

Template variables in more detail

Template variables in more detail

- [Instructor] You already saw that we can make variables available to templates. In our index route, we did that for the page title and also for setting the template that should be rendered with the layout. Template variables are dev way to make any dynamic data available to templates and Express knows three different types depending on their scope. First, you can set the variable directly as we see here on line 10 on our index route. These variables are only available to the particular template for this particular request. Second, Express also knows variables that are globally available to any template for a given request. So they are request global template variables, and they are set on the response object. Typically you would set that via middleware. So let's try this out real quick so I go into server.js and there, after the express static middleware runs and now add a new middleware where app.use and we know…

Contents