Reputation: 4068
Objective: I need to display different templates based on route. In my case it's /edit /new, and I need a condition to display tabs or something else.
In my router.get('/edit' cb)
I tested this: res.url.includes('new')
which returned true. I went inside my header.ejs and ran a condition:
<% if(res.url.includes('new')) { %>
<h1>Something else</h1>
<% } else { %>
<h1>This</h1>
<% } %>
However, it's telling me that res is not defined. My question is this: whats the best way to do this? My first instinct is to just create another header file but that's going to duplicate a lot of code but I may be over optimizing it.
Upvotes: 0
Views: 1846
Reputation: 1509
you need to do res.render('template.ejs', { res: res });
check if u forgot to pass the { res: res }
Upvotes: 4