I have a php variable in my controller and i want to use it in twig. So i do this :
Controller :
$firstLetter = '2017'; //dynamic variable but for the test it's a constant
$build ['list'] = array(
'#theme' => 'liste-adh2',
'#content'=>$result,
'#filters'=>$ListApport,
'#filters2' =>$Listline,
'#test' => $firstLetter, //sending to my template
);
return $build;
Template :
function adh_apport_theme($existing, $type, $theme, $path)
{
return [
'liste-adh2' => [
'variables' => ['content' => NULL, 'filters' => NULL,
'filters2' => NULL,], ['test' => NULL,],
],
];
}
Twig :
{{ test.firstLetter }}
i got nothing in twig and i don't know why.
Thanks for helping.