kalimatas / php-liquid

A PHP port of Ruby's Liquid Templates
http://www.delacap.com/artikel/Liquid-Templates/
MIT License
168 stars 58 forks source link

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

Open phambinh217 opened 6 years ago

phambinh217 commented 6 years ago
/**
 * 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?

sanmai commented 6 years ago

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.

phambinh217 commented 6 years ago

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?

sanmai commented 6 years ago

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

phambinh217 commented 6 years ago

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