What is the difference between include, partial and / or block in templates. Ajs / ajs-locals

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

+7
source share
1 answer

include : just takes the content from the given file and puts it in your include statement. In other words: the file has access to all the variables defined in the file to which it was added.

partials : Just like include , with the difference that a partial only has access to the variables that you pass to it when rendering.

blocks : in your layout, you determine the locations where the contents of your blocks should be. In the file that you render, you define the content for these blocks and determine the layout on which you want to display the contents of your block.

+10
source

All Articles