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

Topic summary

Dynamic snippet rendering with Liquid’s render tag is not supported; render requires a quoted, static snippet name and errors if passed a variable. The include tag can still accept a variable-based name.

A Shopify representative explained this is by design for performance (static dependency analysis and batch loading) and readability. They also clarified that render does not have filters; a briefly working trick using append: “” on a variable relied on a parser bug and was promptly fixed.

Confirmed: include has no deprecation plans currently. One practical pattern shared: capture an include’s output and only print it if it doesn’t contain a Liquid error.

Recommended alternatives to dynamic render:

  • Use a case statement enumerating allowed snippets (e.g., icon variants), potentially centralized in a helper snippet to avoid duplication.
  • Pass variables into a single snippet rather than switching snippets dynamically, when feasible.

Open/ongoing: Developers requested support for safe, constrained dynamic renders (e.g., looping known icon names like ‘icon-’ + handle) to reduce verbosity, noting other templating systems (e.g., Twig) allow this. Some frustration expressed; no change in Shopify’s stance announced.

Summarized with AI on January 6. AI used: gpt-5.

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

2 Likes