How Can I render a snippet this name is defined by a variable?

Highlighted
Shopify Partner
6 0 1

I want to render a snippet this name is defined by a variable.

 

 

{% assign template_name = 'page-' | append: page.template_suffix %}
{% render template_name %}

But it occurs error that show "Syntax error in tag 'render' - Template name must be a quoted string".

 

"include" tag can render a snippet this name is defined by a variable.

 

Why "render" tag can't do it?

 

1 Like
Highlighted
Shopify Partner
1819 211 380

Unfortunately, render doesn't accept dynamic names, most probably by design and taking into consideration the performance impact. 

Sergiu Svinarciuc | CTO @ visely.io
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution!
- To learn more about the awesome stuff we do head over to visely.io or our blog
0 Likes
Highlighted
Tourist
3 0 3

Well, that's a bummer! This would have saved me from having to create a bunch of individual templates. 😫

2 Likes
Highlighted

@Visely-Team @masahiro @jacobgraf 

Would you happen to know any alternatives for this? 

Thank you!

◦ Problem Solved? ✔️ Please click on Accept as Solution and like.
◦ Needing urgent help? I'm available for hire, same day response guaranteed: diego.boarutto.fortes@gmail.com
◦ My app free for limited time: Add a navigation styled like Instagram Stories to your website!
0 Likes
Highlighted
Shopify Partner
1819 211 380

@diego_ezfy nope, not to my knowledge.

Sergiu Svinarciuc | CTO @ visely.io
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution!
- To learn more about the awesome stuff we do head over to visely.io or our blog
0 Likes
Highlighted
Tourist
3 0 3

I ended up double-checking with Shopify to make sure "include" wouldn't be deprecated. They confirmed they have no plans to deprecate it, so, for now, this is the solution I came up with and it works great! This approach will not work with "render".

 

<!-- Product-Specific Content -->
{% assign snippet = 'product-content-' | append: product.handle %}
{% capture snippet_content %}{% include snippet %}{% endcapture %}
{% unless snippet_content contains "Liquid error" %}
    {{ snippet_content }}
{% endunless %}

 

1 Like