php-liquid icon indicating copy to clipboard operation
php-liquid copied to clipboard

What difference between `include`, `include with`, `include for`?

Open phambinh217 opened this issue 6 years ago • 4 comments

/**
 * Includes another, partial, template
 *
 * Example:
 *
 *     {% include 'foo' %}
 *
 *     Will include the template called 'foo'
 *
 *     {% include 'foo' with 'bar' %}
 *
 *     Will include the template called 'foo', with a variable called foo that will have the value of 'bar'
 *
 *     {% include 'foo' for 'bar' %}
 *
 *     Will loop over all the values of bar, including the template foo, passing a variable called foo
 *     with each value of bar
 */

I see in TagInclude, but i don't understant, can you give a example for each case?

phambinh217 avatar Mar 23 '18 02:03 phambinh217

This implementations is expected to behave just like the Ruby's.

Please try referring to the Shopify Liquid docs: https://help.shopify.com/themes/liquid/tags/theme-tags#include

Note that there are at least three variants of Liquid. If something doesn't work here, probably that's because the variant you're looking has diverged from the canonical implementation. However, feel free to open an issue about the case.

sanmai avatar Mar 23 '18 02:03 sanmai

https://help.shopify.com/themes/liquid/tags/theme-tags#include

I test at section include tag parameters

But this lib return result difference shoptity. Is it a bug, or what?

phambinh217 avatar Mar 23 '18 02:03 phambinh217

Can't tell without a code! Please file an issue with an example code. Or even better: make a PR with a failing example.

sanmai avatar Mar 23 '18 02:03 sanmai

I have tow files, named color.liquid, and master.liquid In master.liquid, i include color.liquid

Bellow it code for color.liquid

color: '{{ color }}'
shape: '{{ shape }}'

for master.liquid

{% assign shape = 'circle' %}
{% include 'color' %}
{% include 'color' with 'red' %}
{% include 'color' with 'blue' %}
{% assign shape = 'square' %}
{% include 'color' with 'red' %}

The result I want to have

color: '' shape: 'circle'
color: 'red' shape: 'circle'
color: 'blue' shape: 'circle'
color: 'red' shape: 'square'

But now, result is

color: '' shape: 'circle'
color: '' shape: 'circle'
color: '' shape: 'circle'
color: '' shape: 'square'

Can you check

phambinh217 avatar Mar 23 '18 02:03 phambinh217