【问题标题】:Using EJS without NodeJS在没有 NodeJS 的情况下使用 EJS
【发布时间】:2020-07-20 20:58:12
【问题描述】:

我认为最新的构建版本将允许我在不使用节点的情况下全局使用 ejs,所以我尝试这样做。

但是,当我尝试使用 ejs.renderFile(params...) 时,我得到了错误:

TypeError: exports.fileLoader is not a function

这只是另一个节点模块。有没有办法解决这个问题?

注意:这是我们公司唯一一次使用 EJS,如果没有,请您指出如何渲染 .ejs 文件的好方向。

【问题讨论】:

    标签: java templates build ejs global


    【解决方案1】:

    更新:你可以通过运行来创建一个 EJS 对象

    new EJS({url: some/url/to/file.ejs}).render({dataToPass: data, moreData: secondData});
    

    【讨论】:

      【解决方案2】:

      还有另一种方式,您可以使用render 而不是renderFile,并且您的ejs file 可以作为字符串获取:

      // here using jQuery
      $.get(you_ejs_file_path).then(function (str, status, xhr) {
          const html = ejs.render(str, your_data)); // str is ejs file 
      });
      

      【讨论】:

        猜你喜欢
        • 2014-05-19
        • 2020-10-17
        • 1970-01-01
        • 1970-01-01
        • 2020-09-29
        • 2018-04-15
        • 1970-01-01
        • 1970-01-01
        • 2019-04-13
        相关资源
        最近更新 更多