Liquid, JavaScript, themes, sales channels
Hello everyone,
I've come across a changelog that notes the {% include %} tag is being deprecated in favour of the new {% render %} tag. I'm aware that previous include tags are keeping their functionality, but the new render tag must be included going forward.
The way in which we render our content on pages that aren't the homepage is using a single section that contains the fields for every content block we have. Then we loop through these block and include the required snippet like so:
{% for section in section.blocks %} {%- assign snippet_name = 'section-' | append: section.type -%} {% include snippet_name %} {% endfor %}
However, it seems to not allow me to use a variable in place of the string or allow the snippet access to the data in the parent section which will completely break the site using our current strategy.
Do you have any recommendations on how to solve this issue? Are there new updates coming that will make this change make sense?
Any help would be greatly appreciated!
Hi Matt_Cottis,
try using capture instead of assign:
{% for section in section.blocks %} {%- capture snippet_name -%}section-{{ section.type }}{%- endcapture -%} {% include snippet_name %} {% endfor %}
This works fine for me.
Regards,
Daniel
Hi Leina,
Thank you for replying, but this is an old post that I thought was deleted, here's the new post for reference: https://community.shopify.com/c/Technical-Q-A/Deprecated-include-tag/td-p/608267
Found this workaround. By appending a string (even empty) it transforms the variable into a string.
{%- render variable_name | append: ".liquid" -%}
or
{%- render variable_name | append: "" -%}
Found on this thread.
https://community.shopify.com/c/shopify-design/how-can-i-render-a-snippet-this-name-is-defined-by-a-...
Are you ready to take your business to the next level? Look no further than the latest ...
By SarahF_Shopify Apr 15, 2024We’re keeping the ball rolling to make sure you’re always ahead of the game. So buckle ...
By JasonH Apr 8, 2024Portrait of Stephen positioned next to an image of planet Earth, with the Stephen's World ...
By JasonH Mar 18, 2024