Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Symfony 仅当数组中至少有1个元素时才输出换行div_Symfony_Twig - Fatal编程技术网

Symfony 仅当数组中至少有1个元素时才输出换行div

Symfony 仅当数组中至少有1个元素时才输出换行div,symfony,twig,Symfony,Twig,我有以下(Symfony 2)PHP模板: <?php $messages = $view['session']->getFlashes(); if (count($messages) > 0) : ?> <section id="flashMessages"> <ul> <?php foreach ($messages as $key => $msg) : ?> <li class

我有以下(Symfony 2)PHP模板:

<?php 
$messages = $view['session']->getFlashes();
if (count($messages) > 0) : ?>
<section id="flashMessages">
    <ul>
        <?php foreach ($messages as $key => $msg) : ?>
        <li class="<?php $key ?>">
            <?php echo $msg ?>
        </li>
        <?php endforeach; ?>
    </ul>
</section>
<?php endif; ?>

    {%set messages=app.session.getflash()%}
    {%if messages | length>0%}{{{#或仅“if messages”}
    
      {%表示密钥,消息中的消息%}
    • {{msg}}
    • {%endfor%}
    {%endif%}
    抱歉,写在这里-没有时间测试它。但这应该足以向您展示这些概念

    {% set messages = app.session.getFlashes() %}
    
    {% if messages | length > 0 %} {# or just `if messages` #}
        <section id="flashMessages">
            <ul>
                {% for key, msg in messages %}
                    <li class="{{ key }}">
                        {{ msg }}
                    </li>
                {% endfor %}
            </ul>
        </section>
    {% endif %}