Skip to content

Include other tempates

A very useful feature of ASA2's template syntax is the Template Tags 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:

twig
{% include "template_name" %}

You can also use the template ID which makes the template name change safe:

twig
{% include "2" %}

INFO

When using the template name it has to match exactly!

INFO

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:

twig
<img src="img/rating/blue/{{ CustomerReviewsAverageRating }}.png" />

Template name rating_stars_red:

twig
<img src="img/rating/red/{{ CustomerReviewsAverageRating }}.png" />

Template name rating_stars_green:

twig
<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:

twig
<p>Your template code ...</p>

{% include "rating_stars_blue" %}

ASA2 - The Amazon Affiliate Plugin for WordPress