harrydeluxe / php-liquid

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

Variables don't render in time for usage in context. I.e. cannot be used as Array keys. #32

Open jonnypaper opened 8 years ago

jonnypaper commented 8 years ago

When rendering templates the variables are not being rendered in time for use in context. Example:

<ul class="nav">
  {% for link in navigation.main-navigation.links %}
<li class="cf">
      <a href="{{ link.url }}">{{ link.link_name }}</a> 
     <ul class="nav">
        {% for l in navigation[link.handle].links %}
          <li><a href="{{ l.url }}"{% if l.active %} class="current"{% endif %}>{{ l.link_name }}</a></li>
        {% endfor %}
    </ul>
    </li>
    {% endfor %}
   </ul>

The key issue in the above: When attempting to utilise for loop variables as array keys they fail.

The desired affect (and how Shopify liquid works), is the variable is output as it's value, before further liquid markup is rendered, meaning the variable value can then be used right away in context. In this case, as an array key. The correct output example: {% for l in navigation[my-link-handle-value-after-being-rendered].links %}

Instead it's not rendered and you're left with the variable name itself. Current output example: {% for l in navigation[link.handle].links %}