Nested FOR combined with IF throws exceptions

Hi there,

I have meet a strange behavior in volt. I have this:

        {% if some_var %}
            {% for item in some_var['items'] %}
                {% for object in item %}
                    {% include 'some/partial' with {'object':object} %}
                {% endfor %}
            {% endfor %}
        {% else%}
            Nothing here
        {% endif %}

Throws an exception : Phalcon\Mvc\View\Exception: Unexpected ENDIF

If i remove the second FOR, this works:

        {% if some_var %}
            {% for item in some_var['items'] %}
                // Do  some stuff
            {% endfor %}
        {% else%}
            Nothing here
        {% endif %}

Any idea ?



5.3k

Just some guessing / thinking aloud;

  • does it matter if you add the space: {% else %} ?
  • does it work when you remove the include?
  • does it make a difference if you use square brackets instead of curly ones passing object ?
  • does Volt compile the .php file? (Is the error thrown during tpl compilation, or from the .php?)


32.4k
edited Jun '14

Hi @renskii,

  1. does it matter if you add the space: {% else %} ? -> the space exists, it was a typo mistake - anyway, that does not make any difference
  2. does it work when you remove the include? -> no
  3. does it make a difference if you use square brackets instead of curly ones passing object ? -> no (tested now)
  4. does Volt compile the .php file? (Is the error thrown during tpl compilation, or from the .php?) -> no (error thrown during tpl ) - this is the problem. Throws that exception


32.4k

PS: Phalcon 1.3.2



5.3k

And the nested for without being inside an if structure does work fine?



32.4k

Yes. It works.



5.3k

That certainly looks like a bug in the compiler/parser then?

A couple of thing you could try I guess;

  • try an if withouth else;
  • try different variable names (something else than item & object)..?


32.4k
edited Jun '14

I have tried ... no fix. I'll open an issue...



80

I can confirm this bug in Phalcon 1.3.2: I have a problem with a .volt-file where an {% else %} is ignored as soon as I add two nested {% for %}-loops above it.



80

Bug is also in 1.3.4