带有破折号的 Twig 渲染数组键
当数组键的名称中有破折号时,如何呈现数组键的值?
我有这个片段:
$snippet = "
{{ one }}
{{ four['five-six'] }}
{{ ['two-three'] }}
";
$data = [
'one' => 1,
'two-three' => '2-3',
'four' => [
'five-six' => '5-6',
],
];
$twig = new \Twig_Environment(new \Twig_Loader_String());
echo $twig->render($snippet, $data);
输出为
1
5-6
Notice: Array to string conversion in path/twig/twig/lib/Twig/Environment.php(320) : eval()'d code on line 34
而且它渲染得很好。但在 上抛出错误。four['five-six']
['two-three']