Reputation: 17
I'm trying to pass data object to my HTML page in some tags. This is the code:
<video id="video" class="video-js" poster="<%= data.placeholder %>" >
<source class="link" id="source" src="<%= data.video %>" type='video/mp4'>
and I get an error:
ReferenceError: data is not defined
This is my Express code:
app.get('/lectures/:lecture', (req, res) => {
const index = req.params.lecture;
let data = {
placeholder: `../img/placeholder${index}.svg`,
video: videoURLs[index]
};
res.render('lectures', data);
});
So, how to pass data to tag attribute?
Upvotes: 0
Views: 802
Reputation: 1859
Change your render functionality to:
res.render('lectures', { data });
Actually, it depends on ES version. If you are using ES6 or ES6+, it is okay to use
res.render('lectures', { data });
If ES version lower than 6 (maybe ES5) Use
res.render('lectures', { data: data});
Upvotes: 1