Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is an "include template" in Express/Jade?

This article seems to suggest that there such things as include templates. I've made the obvious Google searches but didn't find any documentation.

What are they?

like image 243
Randomblue Avatar asked Jan 19 '23 02:01

Randomblue


1 Answers

From the Express guide:

The Express view system has built-in support for partials and collections, which are “mini” views representing a document fragment. For example rather than iterating in a view to display comments, we could use partial collection.

So when you have the same "view" for a user in multiple pages, it's more useful to have that view stored in a file and "include" it everywhere. (DRY - Don't Repeat Yourself)

Another example is when have the same layout everywhere and you want to include the rest of the page (for example you could include different headers, footers and body depending on the page).

Here's a good example with Jade, provided in the Express samples:

https://github.com/visionmedia/express/tree/master/examples/jade/views

like image 156
alessioalex Avatar answered Jan 22 '23 05:01

alessioalex