Switching from deprecated {% include %} tag to the {% render %} tag

Matt_Cottis
Shopify Partner
9 0 11

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!

Replies 3 (3)

leinaD
Shopify Partner
46 1 7

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

Matt_Cottis
Shopify Partner
9 0 11

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

 

TheLankyCoder
Shopify Partner
3 0 1

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-...