【发布时间】:2015-12-14 12:44:18
【问题描述】:
这可能相对容易做到,但我是 Twig 新手,我很沮丧。
我正在根据这个答案改编代码:https://stackoverflow.com/a/24058447
数组是通过这种格式用 PHP 制作的:
$link[] = array(
'link' => 'http://example.org',
'title' => 'Link Title',
'display' => 'Text to display',
);
然后通过 twig,我添加 html 到它,然后内爆:
<ul class="conr">
<li><span>{{ lang_common['Topic searches'] }}
{% set info = [] %}
{% for status in status_info %}
{% set info = info|merge(['<a href="{{ status[\'link\'] }}" title="{{ status[\'title\'] }}">{{ status[\'display\'] }}</a>']) %}
{% endfor %}
{{ [info]|join(' | ') }}
</ul>
但我得到了:
Errno [8] 数组到字符串的转换 F:\localhost\www\twig\include\lib\Twig\Extension\Core.php 在第 832 行
当我删除此行时它已修复,但不显示:
{{ [info]|join(' | ') }}
任何想法我可以如何正确地内爆?
** 更新**
使用 Twig 的转储函数它什么也不返回。似乎它甚至没有首先将它加载到数组中。如何将信息加载到新数组中。
【问题讨论】:
标签: php arrays string for-loop twig