Shopify / Shopify/liquid

Using variables as snippet name in render tags

Open
#1,269 14 comments 14 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
11.9k
Forks
1.5k
Avg merge
17h 55m
Merged PRs (30d)
3

Description

Hi!

It seems pretty unreasonable (as an outsider) that I can't do this:

{% assign my_template = 'my-template' %}
{% render my_template %}

I can't understand why render should care if the string it uses is inline or from a variable, so long as its a string.

This feature would be useful for rendering partials based on things that need to be dynamic (For example rendering a different partial if a user was logged in or out) or when you want to make components more generic.

For example, say I have a bunch of svg icons as .liquid files. I want to render them, wrapped with some markup. Rather than edit each icon with repetitive wrapping HTML, I want to create an adapter component and pass in the icon name so I could write:

{% render 'icon', icon_partial: 'cart', text: 'View cart' %}

And then inside snippets/icon.liquid

<div class="icon">
{% render icon_partial %}
{{ text }}
</div>  

Am I being dense? This feels like a step back from include tags.

Cheers

Matt

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by examining the render tag and comparing its behavior with the include tags discussed in the issue. Use the snippets/icon.liquid example to trace how a variable such as icon_partial would be resolved. Done means render accepts a variable snippet name while preserving the demonstrated wrapper and argument behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
web-dev
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.