Skip to content

Commit

Permalink
Views: Fix href (#28887)
Browse files Browse the repository at this point in the history
Pointing to incorrect Express version for now
  • Loading branch information
T0nci authored Oct 1, 2024
1 parent 8234837 commit 3d8ba4b
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion nodeJS/express/views.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ When you hit the `/` route, `res.render("index", { message: "EJS rocks!" });` is

### The locals variable in EJS

In the example above, how did the template file know about the `message` variable? When we render the view, EJS has access to any properties from the object we pass into `res.render`, as well as any properties on [Express's res.locals object](https://expressjs.com/en/5x/api.html#res.locals) (`res.locals` can be useful if you need to pass values to the view in one middleware function, but won't call `res.render` until later in the middleware chain).
In the example above, how did the template file know about the `message` variable? When we render the view, EJS has access to any properties from the object we pass into `res.render`, as well as any properties on [Express's res.locals object](https://expressjs.com/en/4x/api.html#res.locals) (`res.locals` can be useful if you need to pass values to the view in one middleware function, but won't call `res.render` until later in the middleware chain).

EJS will store these properties in an object called `locals`, which you can access in the view. Similarly to the global `window` object in browsers, this allows you to access the `message` variable in the view via `locals.message`, or simply just `message`.

Expand Down

0 comments on commit 3d8ba4b

Please sign in to comment.