Link_to and other view helpers not included in EJS (bundled with Express) for Node.js?

I installed the nodeJS server using the Express web framework using the EJS template engine.

When I try to use the link_to view assistant inside the view, I get a reference error. Is it because I'm doing something wrong, or are view viewers only not included?

I tried the following

 <# link_to("...", "...") #> <#= link_to("...", "...") #> <#- link_to("...", "...") #> 


Note. I have configured custom tags for EJS ...

 server.configure(function () { this.set("view engine", "ejs"); this.set("view options", { open: "<#", close: "#>" }); }); 
+4
source share
2 answers

try:

 var helpers = require('express-helpers') 

and then

 helpers(app); 

in your app.js application if still not working try <%- link_to instead of <%= link_to

+3
source

Add https://github.com/mhayashi/express-helpers , which should fix the problem.

There were problems with them: require ("express helpers"). All functions, however, turned my own. It also works great.

+2
source

Source: https://habr.com/ru/post/1346752/


All Articles