We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

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 position_id, subpositionarray in params[1][params[0]]|sort %} <div>{{position_id}} {% 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 position_id, subpositionarray in params[1][params[0]]|sort %} <div>{{position_id}} </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


9.8k

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



9.8k

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...



9.8k

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

{{boxes2(tier1)}}

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



9.8k
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).