Don't Repeat Yourself - using template includes

You can apply DRY principles to your Perch templates by using our template include functionality.

Perch templates can be included inside one another. If you include a template it then acts as if it was always part of the template and any fields within it will become part of the form created in admin for the content editor to complete and the HTML and content compiled as the output.

To include a template using the following include syntax:

<perch:template path="content/another_template.html" />

This path is relative to the perch/templates directory.

Useful tips

If you are creating templates that will only be used as includes, start their names with an underscore, for example _person.html and the template won’t appear in the list to be selected when setting up a region in Perch admin.

Templates use <perch:content /> tags in content but <perch:app_name /> in apps. You can still use your includes in apps, set them up with <perch:content /> tags and when including them in your app template use the rescope attribute:

<perch:template path="content/another_template.html" rescope="parent" />

If you find yourself copying and pasting code from one template to another, that’s a really good indication that you could be using template includes.

You could even create yourself a set of template includes that you use on all of your projects as a starting point. Creating and reusing more complex templates such as those for Responsive Images and Rich Snippets can save you a lot of time in development.