Includes

Includes in Templates

If you find yourself repeating code in your templates, it’s easy in Harmony to create an include so you can reuse sections of code in multiple templates. To create an include, click the [+] at the bottom left of the Theme sidebar, select ‘Include’, and name your file. Then, fill your include with your reusable code. Includes can take the same code as templates, and have access to the same variables and tags as templates have.

To use an include in a template, header.inc in this example, simply use the include tag provided by our template engine.

{% include 'header' %}

You can also send particular data to an include, if you’d like to reuse the code, but for a different object each time. To send an object along with an include, pass it after the include statement using for, as shown.

{% include 'portfolio' for porfolio_object %}

You will then have access to portfolio_object inside the portfolio include using the variable named after the include, or in this case portfolio.