最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - What is the difference between an include, a partial, andor a block in templating. EJSejs-locals - Stack Overflow

programmeradmin3浏览0评论

I have been using EJS with Express and Node.JS for a little while now and I think I understand the basics. I have experimented with the EJS include function which has allowed me to include one template inside of another. I have also used a library called ejs-locals which provides easy true layout support. One thing I noticed is that ejs-locals also defines partial and block functions which may be used with EJS. I cannot seem to find a good explanation on what the differences between these three concepts are. As far as I can tell they are general concepts to templating and not only EJS. It seems to me that both partial and block are still ways of including other template files, but how do they differ?

I have been using EJS with Express and Node.JS for a little while now and I think I understand the basics. I have experimented with the EJS include function which has allowed me to include one template inside of another. I have also used a library called ejs-locals which provides easy true layout support. One thing I noticed is that ejs-locals also defines partial and block functions which may be used with EJS. I cannot seem to find a good explanation on what the differences between these three concepts are. As far as I can tell they are general concepts to templating and not only EJS. It seems to me that both partial and block are still ways of including other template files, but how do they differ?

Share Improve this question asked Jun 22, 2013 at 23:44 Cory GrossCory Gross 37.2k17 gold badges71 silver badges80 bronze badges 1
  • here is a block implementation in ejs github./dheeraj-br/ejs_layout_implementation – some_groceries Commented Dec 24, 2019 at 18:03
Add a ment  | 

1 Answer 1

Reset to default 17

include: Simply takes the content from the given file and places it where your include statement is. In other words: The file has access to all variables defined in the file it has been included from.

partials: Pretty much the same as include, with the difference that the partial has only access to the variables that you pass to it when rendering.

blocks: In your layout you define locations where your blocks' content should be. In the file you render, you define contents for these blocks and define the layout you would like your block content to be rendered to.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论