Call functions using ejs templates on node

I am trying to create a non-javascript version of my web application using server-side ejs. I am passing an object containing the state of the application to the template, and at some point I want to build the URL using this state object. So basically I want to do something like <% = makeUrl (objectState.data [0])%>

how can i make makeUrl callable from ejs templates?

thanks

edit: I know that I can pass a function as a parameter to a template, but is there a better way?

+8
source share
1 answer

in Express 3, they excluded the concept of dynamic assistants. I believe that passing functions to the template through app.locals is actually the recommended way to do it now. I suppose you already know how, but for someone else with the same question:

in your app.js: app.locals.myFunc = function(arg){...} in your template: <%= myFunc(objectState.data[0]) %> 
+13
source share

All Articles