Oli*_*ton 0 php template-engine twig
我正在使用树枝模板引擎.
我基本上有一个循环通过资源的数组,但是我已经在其中添加了另一个具有密钥的数组,基于顶级数组中的循环索引
所以它看起来像
array("0" => array("a", "b",
"1" => array("d", "e");
Run Code Online (Sandbox Code Playgroud)
和一个去的数组
array("0" => array("food", "drink",
"1" => array("sport", "games");
Run Code Online (Sandbox Code Playgroud)
如果我做{{loop.index}}我从第一个数组得到0和1,这很好
我想要做的是传递{{loop.index}}
到这个for循环
{% for embedData in shareData %}
{{embedData.embed}}
{% endfor %}
Run Code Online (Sandbox Code Playgroud)
所以我可以根据第一个数组键从第二个数组中获取数组值
反正有没有这样做?
您可以通过这种方式实现它,例如假设颜色和团队是两个数组
PHP
$app['colours'] = array('blue', 'green', 'red');
$app['teams'] = array('leafs', 'packers', 'redwings');
Run Code Online (Sandbox Code Playgroud)
视图
{% for colour in app.colours %}
<li>{{loop.index}} {{ colour }} {{ app.teams[ loop.index - 1 ] }}</li>
{% endfor %}
Run Code Online (Sandbox Code Playgroud)
产量
1 blue Leafs
2 green packers
3 red redwings
Run Code Online (Sandbox Code Playgroud)
基本上它们可以通过点符号调用,也可以作为树枝中的数组调用,我的测试没有显示0索引虽然只有1,2,3使用Silex twig扩展来测试