Question: EJS include partials and declare variables for partials - Nodejs

Question

EJS include partials and declare variables for partials - Nodejs

Answers 0
Added at 2016-12-30 21:12
Tags
Question

I have an EJS file where I include a header:

<% include ../partials/header %>

In that header I have some tags (title, description) which have to change depending on the location.

I'm having some issues passing variables to the include.

Controller

var title = 'title',
    description = 'description bla bla';
//...
res.render('home', {title: title, description: description});

View (partials/header)

<meta name="title" content="<%= title %>">
<meta name="description" content="<%= description %>">

Now my problem, when I start the nodejs server the website renders correctly the variables, however I get errors saying that the variables title and description have not been defined.

I'm not sure if I'm doing this the correct way.

Answers to

EJS include partials and declare variables for partials - Nodejs

Source Show
◀ Wstecz