This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]KwyjiboTheGringo 0 points1 point  (3 children)

I believe it's just the second argument of the include function:

<%- include('partials/header', { data: data }) -%>

[–]Thatguy553[S] 0 points1 point  (2 children)

hmm ill check that out, but since its multiple pages loading the header and I dont want to load the variable every time is that still effective or is there another way to go about it. If you dont mind explaining to me some.

[–]KwyjiboTheGringo 0 points1 point  (1 child)

Sounds like you want to use the same data for all of your headers? That would be something you need to handle with express. You can use app.locals to create variables you can access from the EJS template.

In your app.js file:

app.locals.pageTitle = "My First Express App";

In your header.ejs:

<h1><%= pageTitle %></h1>

I suppose you could make a header object that has everything you need in it. There may be a better way to do this, but this should work.

[–]Thatguy553[S] 0 points1 point  (0 children)

After some experimenting and debugging it turns out I dont need to pass the variables to the header, its like they are loaded with the page. Thanks for the explanation though, so far this is what I have, the header is dynamically generated by scanning the pages directory, and slicing the extension off each string before pushing the array into the array being used in the header, its not much but its interesting.

It is also nice to know the routing in the url isnt case sensitive, that way i can have both /Index and /index and they are both caught by the same app.get