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?
Craft CMS Stack Exchange is a question and answer site for administrators, end users, developers and designers for Craft CMS. It only takes a minute to sign up.
Sign up to join this communityYour 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]) %}
include
tag documentation for Twig 1 in comparison.