Posted by rylowry on November 13, 2012 at 5:42pm
I am working with some entities that get themed with a #theme property in a renderable array. I would like to add some theme suggestions, so the entity could be rendered differently if a template is available. Something like this...
<?php
$element = array(
'#theme' => 'entity',
'#theme_hook_suggestions' => array('some_other_function'),
);
?>However, this doesn't seem to work. Can anyone confirm or deny whether such a thing is even possible? I have a feeling this is just wishful thinking.
Comments
Found a solution
I found a solution to my problem. I abandoned #theme_hook_suggestions, which just wasn't working, and ended up using the 'pattern' propery in my hook_theme function.
<?phpfunction hook_theme() {
return array(
'template_page_template' => array(
'render element' => 'elements',
'pattern' => 'template_page_template__',
)
);
}
?>
... and later on in my entity class ....
<?phppublic function buildContent($entity, $view_mode = 'full', $langcode = NULL) {
$content = parent::buildContent($entity, $view_mode, $langcode);
$content['#theme'] = 'template_page_template__' . $entity->type;
return $content;
}
?>
By adding the pattern in hook_theme, bundle type specific templates can get picked up if the are present, but if not, the theme function will fallback to template_page_template. All is good :D