Php变量重写为细枝
我对Twig的重写不起作用。怎么了 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[
<?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 %}