【问题标题】:Why does my array become empty when I pass it to Twig为什么当我将数组传递给 Twig 时数组变为空
【发布时间】:2016-04-22 13:14:44
【问题描述】:

控制器:

$app->get('/', function() use($app){
    $feeds[0] = "test";
    $feeds['name'] = "name";
    $app->render('home.twig', $feeds);
})->name('home');

树枝:

<h2>
{% if feeds %}
    {{ feeds[0] }}
    {{ feeds.name }}
{% else %}
    <h2 style="color: white">TEST</h2>
{% endif %}
</h2>

它显示 TEST 而不是我使用的数组。当我尝试对其进行 var_dump 时,该数组包含数据,但它在 Twig 中显示为空。

【问题讨论】:

  • 也许你应该传递一个数组。 $app-&gt;render('home.twig', array(‘feed’ =&gt; $feeds));
  • 成功了,非常感谢!

标签: php html twig slim


【解决方案1】:

改用这个:

$app->render('home.twig', array('feed' => $feeds));

【讨论】:

    猜你喜欢
    • 2015-03-28
    • 2018-02-01
    • 2014-05-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多