Using variables in the new {% render %} tag

Shopify Partner
8 0 4

This question has stemmed from the Shopify Partners Slack group, where myself and Will Christenson are hunting for an answer.

As Will wrote:

I recently read up on include being deprecated in favor of render ( - but have discovered a MAJOR issue with render, which is that it doesn’t allow you to include a snippet by using a variable for the snippet name (eg. {% render sizeSvg %} ). This breaks a number of development patterns we’ve used in the past, and is very problematic. Can anyone speak to whether or not Shopify is going to address that bug? Or alternatives?

Here is a link to a screenshot of the full thread:

Any takes on how to use a variable name inside the render tag?


There are three ways of doing it: using assigncapture or simply passing the variable value as an argument.

Here is a simple code for you test it out:

1. Create this snippet called custom-test.liquid.

<p>name: {{name}}</p>
<p>test: {{test}}</p>
<p>age: {{age}}</p>

2. At theme.liquid add this right below the <body>:

  {% assign test = 'llama' %}
  {% capture name %}
  {% endcapture %}
  {% render 'custom-test', name: name, age: 10, test: test %}

As you can see, you can simply pass the variables you want by separating them with a comma.

Let me know if this solves your issue!


◦ Problem Solved? ✔️ Please click on Accept as Solution and like.
◦ Tutorials: Minimal theme product pages slideshow | Debut Theme product pages slideshow
◦ Looking to hire a reliable Shopify developer? Same day response:
Shopify Partner
8 0 4

Thank you very much @diego_ezfy, I think that's the answer we were looking for.

I've posted your reply on the original Slack thread from which this question originated from, and once Will has had the chance to confirm this is the solution I'll go ahead and mark your answer as such.

Much appreciated!

Shopify Partner
8 0 4

Unfortunately it seems what we're trying to accomplish isn't possible after all; here's the response over on the Slack thread:

If you're a member of the Shopify Partners Slack Community, you can follow this link to view the thread directly:

Shopify Partner
2571 136 453

Dynamic variable includes while useful should be avoided and considered for refactoring in legacy code.

I'd consider it an anti-pattern for any theme intended for merchants, since it's confusing to merchants(and developers) as to which snippet is actually being called.

If you need this level of dynamism consider an intermediary snippet that has described parameters used in switch statement to render final snippets.

We'll probably start seeing more of that for media objects , and yes irony of ironies avoiding such switch statements is the exact reason we want to use dynamic variable includes.


For a series of snippets ,intended for enumerable object's , use {% render %}'s for parameter in the switch

Problem Solved? ✔️Accept and ? Like the solution so you can help others.
Buy me a coffee ☕ or donate to
Confused? Busy? Buy a custom solution
Shopify Partner
16 0 6

Oh Noooo.

Because of this change (render), I have write to 100 lines instead of 1 line.

It looks like it is not an upgrade, it is an downgrade.

Please work on it asap.