Cphalcon: Volt: ELSE within multiples FOR's and IF's not matching brackets

Created on 23 Sep 2015  路  3Comments  路  Source: phalcon/cphalcon

Hello,

When emulating a switch within a FOR using IF's, then using 2 nested for-loops the last nested for has a conflict with {% else %} from the IF conditions.

I'm using version 2.0.7.

Volt code:

{% set filters = ["category":["type":"category","name":"Category","values":[["name":"Men","nbr":1,"children":[["name":"Shoes","nbr":1]]],["name":"Women","nbr":1,"children":[["name":"Clothing","nbr":1]]]]],"price":["type":"price","name":"Price","values":["min":1,"max":999]]] %}

{% for filter in filters %}
    <fieldset>
        <legend>type: {{ filter['type'] }}</legend>

        {% if filter['type'] == 'price' %}
            min: {{ filter['values']['min'] }} - max: {{ filter['values']['max'] }}<br>
        {% elseif filter['type'] == 'category' %}

            {% for division in filter['values'] %}
                division: {{ division['name'] }} ({{ division['nbr'] }})<br>

                {# FOR conflicts with IF ELSE!?! #}
                {% for department in division['children'] %}
                    > department: {{ department['name'] }} ({{ department['nbr'] }})<br>
                {% endfor %}

            {% endfor %}

        {% else %}
            {% for value in filter['values'] %}
                {{ value['name'] }} ({{ value['nbr'] }})<br>
            {% endfor %}

        {% endif %}
    </fieldset>
    <br>
{% endfor %}

Output:

<?php $filters = array('category' => array('type' => 'category', 'name' => 'Category', 'values' => array(array('name' => 'Men', 'nbr' => 1, 'children' => array(array('name' => 'Shoes', 'nbr' => 1))), array('name' => 'Women', 'nbr' => 1, 'children' => array(array('name' => 'Clothing', 'nbr' => 1))))), 'price' => array('type' => 'price', 'name' => 'Price', 'values' => array('min' => 1, 'max' => 999))); ?>

<?php foreach ($filters as $filter) { ?>
    <fieldset>
        <legend>type: <?php echo $filter['type']; ?></legend>

        <?php if ($filter['type'] == 'price') { ?>
            min: <?php echo $filter['values']['min']; ?> - max: <?php echo $filter['values']['max']; ?><br>
        <?php } elseif ($filter['type'] == 'category') { ?>

            <?php foreach ($filter['values'] as $division) { ?>
                division: <?php echo $division['name']; ?> (<?php echo $division['nbr']; ?>)<br>

                <?php foreach ($division['children'] as $department) { ?>
                    > department: <?php echo $department['name']; ?> (<?php echo $department['nbr']; ?>)<br>
                <?php } ?>

            <?php } ?>


            <?php foreach ($filter['values'] as $value) { ?>
                <?php echo $value['name']; ?> (<?php echo $value['nbr']; ?>)<br>
            <?php } ?>

        <?php } ?>
    </fieldset>
    <br>
<?php } ?>

Expected:

<?php $filters = array('category' => array('type' => 'category', 'name' => 'Category', 'values' => array(array('name' => 'Men', 'nbr' => 1, 'children' => array(array('name' => 'Shoes', 'nbr' => 1))), array('name' => 'Women', 'nbr' => 1, 'children' => array(array('name' => 'Clothing', 'nbr' => 1))))), 'price' => array('type' => 'price', 'name' => 'Price', 'values' => array('min' => 1, 'max' => 999))); ?>

<?php foreach ($filters as $filter) { ?>
    <fieldset>
        <legend>type: <?php echo $filter['type']; ?></legend>

        <?php if ($filter['type'] == 'price') { ?>
            min: <?php echo $filter['values']['min']; ?> - max: <?php echo $filter['values']['max']; ?><br>
        <?php } elseif ($filter['type'] == 'category') { ?>

            <?php foreach ($filter['values'] as $division) { ?>
                division: <?php echo $division['name']; ?> (<?php echo $division['nbr']; ?>)<br>

                <?php foreach ($division['children'] as $department) { ?>
                    > department: <?php echo $department['name']; ?> (<?php echo $department['nbr']; ?>)<br>
                <?php } ?>


            <?php } ?>

        <?php } else { ?>
            <?php foreach ($filter['values'] as $value) { ?>
                <?php echo $value['name']; ?> (<?php echo $value['nbr']; ?>)<br>
            <?php } ?>

        <?php } ?>
    </fieldset>
    <br>
<?php } ?>
bug stale medium

Most helpful comment

Just best will be if someone will provide some PR with test.

All 3 comments

If I use elseif statement with nested loop, I have same error

What about latest 3.* version? Version 2 is unsupported and is very unlikely to be looked at.

Just best will be if someone will provide some PR with test.

Was this page helpful?
0 / 5 - 0 ratings