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
From the course: Building a Website with Node.js and Express.js
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
-
-
-
-
-
-
(Locked)
Create a site-wide layout6m 54s
-
(Locked)
Using partials with EJS4m 56s
-
(Locked)
Template variables in more detail5m 57s
-
(Locked)
Looping through lists in templates11m 33s
-
(Locked)
Creating a list page6m 4s
-
(Locked)
Using parameter routes7m 9s
-
(Locked)
Challenge: Partials and lists2m 20s
-
(Locked)
Solution: Partials and lists8m 46s
-
(Locked)
-
-
-
-