twig - How to print value with dynamic variable -
datas
$datas = [ 'first' => [ 1 => [ 'count' => 20 ], 2 => [ 'count' => 100 ] ] ];
i have data load database, result like:
$rows = [ 1 => 'aaaa', 2 => 'bbbb' ];
i loop rows in view
{% key, row in rows %} {{ datas.first.key.count }} // empty {% endfor %}
i want use rows key show datas count, it's not work, datas.first.1.count print correct result
in php
$datas = [ 'first' => [ 1 => [ 'count' => 20 ], 2 => [ 'count' => 100 ] ] ]; $rows = [ 1 => 'aaaa', 2 => 'bbbb' ]; foreach ($rows $key => $value) { echo 'count :'.$datas['first'][$key]['count']; }
this sample on php
i think (not clear) want this:
{% row in datas.first %} {{ row.count }} // count value {% endfor %}
here working twigfiddle:
Comments
Post a Comment