【问题标题】:Nodejs, EJS helper functions not work for include function.!Nodejs,EJS 辅助函数不适用于包含函数。!
【发布时间】:2016-04-02 01:53:41
【问题描述】:

我使用nodeJS并表达v3*,

我想在某个辅助函数中执行include("someFile.ejs"),以便可以从任何 EJS 模板调用我?

我在 app.js 中的代码,服务器端:

app.locals.getFile= function(){ 

  include("someFile.ejs")
  include("someOneFile.ejs")
  include("someTwoFile.ejs")

  return 'all is well';

}

我在 Ejs 中的代码:

<% getFile() %>

所以问题是:我希望 include("someFile.ejs") 在 ejs 文件上运行,但它没有!我该怎么办?

【问题讨论】:

    标签: javascript node.js express ejs


    【解决方案1】:

    这可能有效

    app.locals.getFile = function()
    {
        return `
            <%- include("someFile.ejs") %>
            <%- include("someOneFile.ejs") %>
            <%- include("someTwoFile.ejs") %>
            all is well
        `
    }
    

    【讨论】:

      【解决方案2】:

      你可以试试这个

      app.locals.getFile= function(){ 
      
      <%include someOneFile%>
      <%include someOneFile%>
      <%include someOneFile%>
      return 'all is well';
      
      }
      

      【讨论】:

      • 请编辑您的帖子以改进它。不要为此目的使用 cmets。
      • 感谢@ashish-mulani,但是当我测试它时,我遇到了语法错误
      猜你喜欢
      • 2012-10-24
      • 2020-10-21
      • 2012-12-06
      • 2013-05-11
      • 2017-11-03
      • 2015-03-08
      • 1970-01-01
      • 1970-01-01
      • 2023-03-30
      相关资源
      最近更新 更多