<p>Your code should work if you remove the quotation marks enclosing your variable.</p>

<pre><code>{% set embedAsset = entry.productId %}
{% include embedAsset %}
</code></pre>

<p>If you want, you can use string concatenation to add a path or extension to it.</p>

<pre><code>{% set embedAsset = '_products/' ~ entry.productId ~ '.html' %}
{% include embedAsset %}
</code></pre>

<p>You could also add a "fallback template", that loads in case your dynamic template does not exist (read the <a href="http://twig.sensiolabs.org/doc/functions/include.html" rel="nofollow noreferrer">Twig docs</a> for more info about this).</p>

<pre><code>{% set embedAsset = '_products/' ~ entry.productId ~ '.html' %}
{% set defaultAsset = '_products/default.html' %}
{% include([embedAsset, defaultAsset]) %}
</code></pre>

CC BY-SA 3.0
2015-01-21T12:24:04.613Z
Belting! thank you very much for the super swift reply
magicspon
CC BY-SA 3.0
2017-03-27T15:28:37.687Z
@carlcs A variable should be in single parenthesis according [to Twig docs](http://twig.sensiolabs.org/doc/2.x/functions/include.html#include).
Dominik Krulak
CC BY-SA 3.0
2017-03-28T08:54:07.990Z
@DominikK interesting, it seems like this is new for Twig 2. See the [`include` tag](http://twig.sensiolabs.org/doc/1.x/tags/include.html) documentation for Twig 1 in comparison.
carlcs
CC BY-SA 3.0
2015-01-21T11:46:36.903Z
2018-01-19T09:14:26.860Z
2018-01-19T09:14:26.860Z
carlcs
<p>I have a series of structure items, each with a product id, based on this id I would like to load in an additional template.</p>

<p>Something like this:</p>

<pre><code>{% set embedAsset = entry.productId %}
{% include "embedAsset" %}
</code></pre>

<p>Any ideas?</p>

<templating><include>
How to dynamically set an include template
# How to dynamically set an include template

(Asked by: username_0 on 2015-01-21)

I have a series of structure items, each with a product id, based on this id I would like to load in an additional template.
Something like this:
{% set embedAsset = entry.productId %}
{% include "embedAsset" %}

Any ideas?

**Tags:** templating, include

---

## 1 answers

### Answer by username_1 on 2015-01-21. Score: 9 | Accepted answer

Your code should work if you remove the quotation marks enclosing your variable.
{% set embedAsset = entry.productId %}
{% include embedAsset %}

If you want, you can use string concatenation to add a path or extension to it.
{% set embedAsset = '_products/' ~ entry.productId ~ '.html' %}
{% include embedAsset %}

You could also add a "fallback template", that loads in case your dynamic template does not exist (read the Twig docs for more info about this).
{% set embedAsset = '_products/' ~ entry.productId ~ '.html' %}
{% set defaultAsset = '_products/default.html' %}
{% include([embedAsset, defaultAsset]) %}

> **Comments:**
> **username_0**: Belting! thank you very much for the super swift reply  
> **username_2**: @carlcs A variable should be in single parenthesis according [to Twig docs](http://twig.sensiolabs.org/doc/2.x/functions/include.html#include).  
> **username_1**: @DominikK interesting, it seems like this is new for Twig 2. See the [`include` tag](http://twig.sensiolabs.org/doc/1.x/tags/include.html) documentation for Twig 1 in comparison.  

---

