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

10,684

Solution 1

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

Solution 2

https://github.com/visionmedia/jade

It's there in one of the H2 headings.

Share:
10,684
Randomblue
Author by

Randomblue

Updated on June 08, 2022

Comments

  • Randomblue
    Randomblue almost 2 years

    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?

  • Falcon
    Falcon over 10 years
    the example code is very helpful. in short, the syntax is include viewName