Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/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
Php变量重写为细枝_Php_Variables_Twig - Fatal编程技术网

Php变量重写为细枝

Php变量重写为细枝,php,variables,twig,Php,Variables,Twig,我对Twig的重写不起作用。怎么了 PHP来源: <?php foreach ($datas as $data) { ?> <?php if ($data['information_id'] == $info_id) { ?> <a href="<?php echo $data['href']; ?>" class="list-group active"><?php echo $data[

我对Twig的重写不起作用。怎么了

PHP来源:

<?php foreach ($datas as $data) { ?>
          <?php if ($data['information_id'] == $info_id)  { ?>
                <a href="<?php echo $data['href']; ?>" class="list-group active"><?php echo $data['title']; ?></a>              
             <?php } else { ?>
             <a href="<?php echo $data['href']; ?>" class="list-group"><?php echo $data['title']; ?></a> 
             <?php } ?> 
             <?php } ?>
重写到细枝:

    {% for datas in data %}
            {% if {{ attribute(data,information_id) }} == info_id %}
             <a href="{{ data.href }}" class="list-group active">{{ data.title }}</a>
             {% else %}
             <a href="{{ data.href }}" class="list-group">{{ data.title }}</a>  
             {% endif %}           
        {% endfor %}
尝试:

当您将变量输出到页面时,只需要在{{}中包装变量。不在{%I%%}语句的中间。

此外,我还将{%替换为数据%}中的数据,将{%替换为数据%}中的数据。我假设datas是数组,data是每个单独的项


请提供更多详情。例如,到目前为止您尝试了什么?请通读{data.information_id}/{{data['information_id']}/{{attributedata,information_id}}
{% for data in datas %}
        {% if attribute(data,information_id) == info_id %}
             <a href="{{ data.href }}" class="list-group active">{{ data.title }}</a>
        {% else %}
             <a href="{{ data.href }}" class="list-group">{{ data.title }}</a>  
        {% endif %}           
{% endfor %}