Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

if for for error, if for ok

php 5.6 phalcon 2.0.7. Briefly because i am doing something else now. In a macro i have an error Unexpected ENDIF in ...volt 3 nested for but for not nested i didn't have any - it is about syntax error but it shouldn't be if true is for academic purposes :) {% if true %} {% for positionid, subpositionarray in params[1][params[0]]|sort %} <div>{{positionid}} {% for priority, priorityarray in subpositionarray|sort %} <div>{{priority}} {% for html in priorityarray %} <div>{{html}}</div> {% endfor %} </div>
{% endfor %} </div>
{% endfor %} {% endif %} This is ok {% if true %} {% for positionid, subpositionarray in params[1][params[0]]|sort %} <div>{{positionid}} </div>
{% endfor %} {% endif %}

Macro is loaded in partial from volt extended class before anyghing else is loaded.

edited Sep '15

Same environment (php 5.6 on debian + phalcon 2.0.7). I changed your var names a bit, but the syntax checks out for me without any error...

    public function fooAction()
    {
        $this->view->tier1 = [
            2 => [
                3 => ['2:3:foo','2:3:bar'],
                1 => ['2:1:foo','2:1:bar'],
            ],
            1 => [
                2 => ['1:2:foo','1:2:bar'],
                1 => ['1:1:foo','1:1:bar'],
            ],
        ];
    }
{% if true %}
    {% for k1, tier2 in tier1|sort %}
        <div>
            #1: {{ k1 }}
            {% for k2, tier3 in tier2|sort %}
                <div>
                    #2: {{ k2 }}
                    {% for item in tier3 %}
                        <div>{{ item }}</div>
                    {% endfor %}
                </div>
            {% endfor %}
        </div>
    {% endfor %}
{% endif %}
#1: 2
#2: 1
2:1:foo
2:1:bar
#2: 3
2:3:foo
2:3:bar
#1: 1
#2: 1
1:1:foo
1:1:bar
#2: 2
1:2:foo
1:2:bar


5.1k

I ll check it maybe this is about that simple name like param instead params[1][params[0]] :)



5.1k

I forgot to say that this wrapping around if causes error. It's ok as long as there is no if there. I am checking...



5.1k

Could you try, please, to put it in a macro (your example behaves the same way when in a macro at least i don't see what else is happening)

{%- macro boxes2(tier1) %}
{% if true %}
    {% for k1, tier2 in tier1|sort %}
        <div>
            #1: {{ k1 }}
            {% for k2, tier3 in tier2|sort %}
                <div>
                    #2: {{ k2 }}
                    {% for item in tier3 %}
                        <div>{{ item }}</div>
                    {% endfor %}
                </div>
            {% endfor %}
        </div>
    {% endfor %}
{% endif %}
{%- endmacro %}

Then invoke it like this ```php {{boxes2(tier1)}}

```

That thread is about 1.3.2... and as I've show you, nested for iterations does work :P



5.1k
edited Sep '15

Yes, yes, i know, but have you placed the code with if for for for into a macro function and invoked it with tier1 variable? The example of a macro called boxes i placed above. Maybe it has meaning whether the code is in a macro or not.

And this is possiblly not important but the macros file is loaded in an extended volt class before almost anything else is loaded. But this final clue rather is to be ignored (extended \Phalcon\Mvc\View\Engine\Volt).