Skip to content
Advertisement

Tag: ejs

Passing variable from app.js to ejs file into a script tag

I’m trying to pass variable which is defined in app.js into a script tag inside and ejs file. So the app.js in short looks like this: The variable I want to pass is the app.locals.myVar, acutally this method doesnt work and I still get that myVar is not defined in ejs file The ejs file is here: As you can

can’t for loop in ejs

Im trying to loop in ejs template, but unexpectedly keep getting these error In normal javascript In javascript it works just fine. The problem is in ejs, I have two versions that I tried, both of them are not working First Attempt Second attempt It keeps telling that Cannot read property ‘title’ of undefined, but if I change j <

Express and ejs <%= to render a JSON

In my index.ejs I have this code: In my node I have However, on the page I obtain and if I write I obtain: Is there a way to pass a JSON that will be JS readable? Answer Oh that was easy, don’t use <%=, use <%- instead. For example: The first one will render in HTML, the second one

Advertisement