小编Chr*_*s98的帖子

Twig Array转换为字符串

这可能相对容易,但我是新手,我很沮丧.

我正在调整这个答案的代码:https://stackoverflow.com/a/24058447

该数组是通过以下格式在PHP中创建的:

$link[] = array(
       'link' => 'http://example.org',
       'title' => 'Link Title',
       'display' => 'Text to display',
);
Run Code Online (Sandbox Code Playgroud)

然后通过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>
Run Code Online (Sandbox Code Playgroud)

但是我得到了:

Errno [8]在832行的F:\ localhost\www\twig\include\lib\Twig\Extension\Core.php中进行字符串转换

删除此行时,它已修复,但不显示:

{{ [info]|join(' | ') }}
Run Code Online (Sandbox Code Playgroud)

有什么想法我怎么能正确破坏这个?

**更新**

使用Twig的转储功能,它什么都不返回.它似乎甚至没有首先将它加载到阵列中.如何将信息加载到新数组中.

php arrays string for-loop twig

16
推荐指数
3
解决办法
4万
查看次数

标签 统计

arrays ×1

for-loop ×1

php ×1

string ×1

twig ×1