13

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?

4

1 回答 1

16

include:只需从给定文件中获取内容并将其放在您的include语句所在的位置。换句话说:该文件可以访问包含它的文件中定义的所有变量。

partials: 与 几乎相同include,不同之处在于部分只能访问您在渲染时传递给它的变量。

blocks:在您的布局中,您可以定义块内容的位置。在您呈现的文件中,您定义这些块的内容并定义您希望将块内容呈现到的布局。

于 2013-06-23T16:09:11.173 回答