I've created a custom entity and a template for it.
path to template /modules/custom/my_module/templates.
My theme_hook()
/**
* Implements hook_theme().
*/
function my_module_theme($existing, $type, $theme, $path) {
return [
'my_module' => [
'path' => $path . '/templates',
'template' => 'my-module',
'variables' => [
'#my_entity' => '',
],
],
];
}
My preprocess
/**
* Prepares variables for My Module templates.
*
* Default template: my-module.html.twig.
*
* @param array $variables
* An associative array containing:
* - elements: An associative array containing the user information and any
* - attributes: HTML attributes for the containing element.
*/
function template_preprocess_my_template(array &$variables) {
// Fetch my_entity Entity Object.
$my_entity = $variables['elements']['#my_entity'];
// Helpful $content variable for templates.
foreach (Element::children($variables['elements']) as $key) {
$variables['content'][$key] = $variables['elements'][$key];
}
}
But all I get is the user object nothing else.
Did I miss something?
#
.