Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-01-21T12:24:04.613Z
Answers.Text: Belting! thank you very much for the super swift reply
Answers.UserDisplayName: magicspon
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-03-27T15:28:37.687Z
Answers.Text: @carlcs A variable should be in single parenthesis according [to Twig docs](http://twig.sensiolabs.org/doc/2.x/functions/include.html#include).
Answers.UserDisplayName: Dominik Krulak
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-03-28T08:54:07.990Z
Answers.Text: @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.
Answers.UserDisplayName: carlcs
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-01-21T11:46:36.903Z
Answers.LastActivityDate: 2018-01-19T09:14:26.860Z
Answers.LastEditDate: 2018-01-19T09:14:26.860Z
Answers.UserDisplayName: carlcs
Body: <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>
  
Tags: <templating><include>
Title: How to dynamically set an include template
ThreadText: # 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](http://twig.sensiolabs.org/doc/functions/include.html) 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**: @username_1 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.  
  
  ---
  
  