render
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.
When you render a snippet using the render
tag, you can't use the include
tag
inside the snippet.
Syntax
The name of the snippet to render, without the .liquid
extension.
render tag parameters
Syntax
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.
Passing variables to a snippet
Syntax
Variables that have been created outside of a snippet can be passed to a snippet as parameters on the render
tag.
Any changes that are made to a passed variable apply only within the snippet.
with
Syntax
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.