Skip to main content

render

Renders a snippet or app block.

Inside snippets and app blocks, you can't directly access variables that are created outside of the snippet or app block. However, you can specify variables as parameters to pass outside variables to snippets.

While you can't directly access created variables, you can access global objects, as well as any objects that are directly accessible outside the snippet or app block. For example, a snippet or app block inside the product template can access the product object, and a snippet or app block inside a section can access the section object.

Outside a snippet or app block, you can't access variables created inside the snippet or app block.


Note

When you render a snippet using the render tag, you can't use the include tag inside the snippet.


Syntax

{% render 'filename' %}
filename

The name of the snippet to render, without the .liquid extension.

Anchor to render

render tag parameters

Syntax

{% render 'filename' for array as item %}

You can render a snippet for every item in an array using the for parameter. You can also supply an optional as parameter to be able to reference the current item in the iteration inside the snippet. Additionally, you can access a forloop object for the loop inside the snippet.

Anchor to Passing variables to a snippet

Passing variables to a snippet

Syntax

{% render 'filename', variable: value %}

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


Note

Any changes that are made to a passed variable apply only within the snippet.


Syntax

{% render 'filename' with object as name %}

You can pass a single object to a snippet using the with parameter. You can also supply an optional as parameter to specify a custom name to reference the object inside the snippet. If you don't use the as parameter to specify a custom name, then you can reference the object using the snippet filename.

Was this page helpful?