Skip to content

render ​

Last updated View as Markdown

Renders a snippet by the given name.

liquid
{% render 'snippet_name' %}

Variables ​

A snippet can read the variables of the template, section or snippet that renders it. Variables that you create in the snippet with assign or capture are also visible after the render tag.

In other Liquid implementations, a rendered snippet can read only global objects and the parameters you pass. If you pass every variable that a snippet uses, the snippet works the same everywhere. For example, write {% render 'card', product: product %} instead of {% render 'card' %} inside a for product in ... loop.

Render tag parameters ​

for ​

You can render a snippet for every item in an array with the for parameter. Inside the snippet, the current item has the name of the snippet, or the name you give with as. The snippet can also read a forloop object for the loop.

liquid
{% render 'snippet_name' for array as item %}

Passing variables to a snippet ​

Variables that have been created outside of a snippet can be passed to a snippet as parameters on the render tag.

liquid
{% render 'snippet_name', variable: value %}

with ​

You can pass a single object to a snippet with the with parameter. Inside the snippet, the object has the name of the snippet, or the name you give with as.

liquid
{% render 'snippet_name' with object as name %}