Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.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
Twig 如何在细枝上进行foreach循环_Twig - Fatal编程技术网

Twig 如何在细枝上进行foreach循环

Twig 如何在细枝上进行foreach循环,twig,Twig,这里我附上了截图,在第二部分中有2行。我只需要显示一行自定义代码条件,若我从管理端禁用,它将正常工作,但我需要启用和禁用循环条件只显示行。这是我的密码 <div class="col-md-12" >{% for module in modules %}<div class="img-responsive"> {{ module }} {% endfor %}</div></div>

这里我附上了截图,在第二部分中有2行。我只需要显示一行自定义代码条件,若我从管理端禁用,它将正常工作,但我需要启用和禁用循环条件只显示行。这是我的密码

<div class="col-md-12" >{% for module in modules %}<div class="img-responsive">
                {{ module }}
              {% endfor %}</div></div>
          </div>
{%用于模块中的模块%}
{{module}}
{%endfor%}
循环中有一个特殊的循环,让您可以跟踪索引和更多内容。在您的例子中,
loop.index

<div class="col-md-12" >
    {% for module in modules %}
        <div class="img-responsive">
            {# Replace 1 with a specific index you want to use as condition #}
            {% if loop.index == 1 %}
                {{ module }}
            {% else %}
                No module
            {% endif %}
        </div>
    {% endfor %}
</div>

{模块%中模块的%s}
{#将1替换为要用作条件的特定索引#}
{%if loop.index==1%}
{{module}}
{%else%}
无模块
{%endif%}
{%endfor%}

看看@prasanna,如果这不是您想要的,您能详细说明问题是什么吗?@prasanna我已经进一步更新了我的示例,当前代码有一个条件,只打印循环中的第一个模块,否则它将打印“无模块”。我不知道你想要什么,请试着解释一下你想要的结果。@prasanna它解决了你的问题吗?如果是这样,请随意将答案标记为可接受的解决方案:)我真的不明白你在问什么,请用你想要的输出的示例更新你的问题。在执行此操作之前,请确保阅读并遵循给定的指导原则nex:array(a,b,c,d,e,f)如果我们想获得(a)=>1st index意味着我们写{%If loop.first==1%},如果我们想获得(b)=>2nd index意味着我们写{%If loop.index==1%},如果我们想获得(f)last index意味着我们写{%If loop.last==1%},那么如何获取(c,d,f)索引值,我需要单独的数据