Include other tempates¶
A very useful feature of ASA2’s template syntax is the include tag. It allows you to include one or more templates in another. This helps us keeping our template code clean and separated.
For example you can create template snippets, like for galleries, price information or different rating styles and inlcude these snippets in your main templates.
The include syntax is easy:
{% include "template_name" %}
You can also use the template ID which makes the template name change safe:
{% include "2" %}
Note
When using the template name it has to match exactly!
Note
Nested includes are not possible.
Example¶
If you have different rating stars designs, you can prepare a template snippet for every one.
Template name rating_stars_blue
:
<img src="img/rating/blue/{{ CustomerReviewsAverageRating }}.png" />
Template name rating_stars_red
:
<img src="img/rating/red/{{ CustomerReviewsAverageRating }}.png" />
Template name rating_stars_green
:
<img src="img/rating/green/{{ CustomerReviewsAverageRating }}.png" />
Now in your main template you can include one of them. Let’s say for your new template you want to use the blue ratings stars, use this include
statement:
<p>Your template code ...</p>
{% include "rating_stars_blue" %}