Layouts in Express 3 and EJS

前端 未结 3 850
野的像风
野的像风 2021-02-01 22:49

In version 3 of Express some features were removed:

the concept of a \"layout\" (template engine specific now)
partial() (template engine specific)
3条回答
  •  梦毁少年i
    2021-02-01 23:11

    I struggled with this as well. So I put up a github project with an example for ejs and dustjs.

    https://github.com/chovy/express-template-demo

    I'm not sure the difference between a partial and an include, you don't need to explicitly pass data to an include. Not sure why you would want a partial.

    But for a layout, you just specify a block like this:

    //layout.ejs
    
    <%- body %>
    
    
    //page1.ejs
    <% layout('layout') -%>
    This is loaded from page 1 and overrides <%- body %> in the layout.ejs.
    

    If anyone wants to add more examples, just submit a pull request.

提交回复
热议问题