mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-12 23:40:45 -07:00
Added Multiple Drops example, added comments in the code to clarify a string is needed for assigns
+11
-2
@@ -62,8 +62,17 @@ Returns the drop instance.
|
|||||||
file = File.read(product_view.liquid)
|
file = File.read(product_view.liquid)
|
||||||
template = Liquid::Template.parse(file)
|
template = Liquid::Template.parse(file)
|
||||||
drop = ProductDrop.new(@product)
|
drop = ProductDrop.new(@product)
|
||||||
template.render('product' => drop)
|
template.render('product' => drop) # Please note the hash assignment is a string, not a symbol
|
||||||
|
|
||||||
### View
|
### View
|
||||||
|
|
||||||
Viewing product: {{ product.name }} <br/><br /> {{ product.description }} <br /> £{{ product.price }}
|
Viewing product: {{ product.name }} <br/><br /> {{ product.description }} <br /> £{{ product.price }}
|
||||||
|
|
||||||
|
### Multiple Drops
|
||||||
|
You can use assigns to assign multiple drops before you call render. This can be useful to keep the render statement clean, while still maintaining functionality.
|
||||||
|
|
||||||
|
file = File.read(product_view.liquid)
|
||||||
|
template = Liquid::Template.parse(file)
|
||||||
|
template.assigns['product'] = ProductDrop.new(@product) # Please note the hash assignment is a string, not a symbol
|
||||||
|
template.assigns['collections'] = CollectionDrop.new(@product.collections)
|
||||||
|
template.render
|
||||||
|
|||||||
Reference in New Issue
Block a user