I'm trying to pass a variable from a custom module to a custom theme. I have a Controller class in a custom module
<?php
namespace Drupal\course_catalog\Controller;
use Drupal\Core\Controller\ControllerBase;
Class CourseCatalog extends ControllerBase {
public function build() {
$item = 'Test content';
return [
'#theme' => 'region__content',
'#item' => $item,
];
}
}
And this hook_theme()
in the .module
<?php
/**
* Implements hook_theme().
*/
function course_catalog_theme() {
return [
'region__content' => [
'variables' => ['item' => NULL]
]
];
}
Lastly I have my custom theme I have region--content.html.twig
<h2>Content: {{ item }}</h2>
This item
value never render on the page. Have I missed something here ?
course-list.html.twig
. Didn't work with that either.templates
folder? Have you tried using{{ dump(item) }}
to see what is inside the variable? And have you cleared Drupal cache?