【问题标题】:include ejs with statement将 ejs 包含在语句中
【发布时间】:2021-12-09 17:23:17
【问题描述】:

我想知道是否只有当用户登录时才可以在 ejs 中包含我的标题。 我试过这个:

<% if(connect) { %>
    <%- include('../partials/header-login'); %>
<%  } else { %>
    <%- include('../partials/header'); %>
<% } %>

有人有解决办法吗?

【问题讨论】:

    标签: javascript nodes ejs


    【解决方案1】:

    你在正确的轨道上! 来自文档:

    HTML模板:

        <% if (user) { %>   <h2><%= user.name %></h2> <% } %>
    

    用法:

    let template = ejs.compile(str, options);
    template(data);
    // => Rendered HTML string
    
    ejs.render(str, data, options);
    // => Rendered HTML string
    
    ejs.renderFile(filename, data, options, function(err, str){
        // str => Rendered HTML string
    });
    

    更多细节可以看官方文档:https://ejs.co/#docs

    为了更好地使用 stackoverflow,您可以参考本指南:https://stackoverflow.com/help/how-to-ask

    【讨论】:

      猜你喜欢
      • 2017-07-12
      • 2021-12-24
      • 2013-10-18
      • 2018-02-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-14
      • 2011-02-13
      相关资源
      最近更新 更多