We have a content type that is added to the drupal system Programmatically when we install one of our custom modules. Essentially the module handle incoming property data from a 3rd party and creates a node entity for each property.
The content type created is named properties
and as such its template suggestion shown in Twig debugging is node--properties--full.html.twig
, see below:
I am creating a second custom module called lrg_property_display
and my intention is that this module will handle all the rendering related functionality as I want to keep the API import related functionality separate from the rendering. My module structure is shown below:
I have created my module and followed a couple sites suggestions that I simply create a template file in my module and in the .module file implement the HOOK_THEME
method, which I have done as shown:
function lrg_property_display_theme($existing, $type, $theme, $path)
{
$theme['node__property_display__full'] = [
'template' => 'node--property-display--full',
'base hook' => 'node'
];
return $theme;
}
Clearing cache and refreshing the page though is showing that the theme is not been applied.
Where am I going wrong with this please? I basically need the node--property-display--full.html.twig
template within the module to be used whenever a node of the type Properties
is viewed.
UPDATE
I added the following code to my theme file (Theme name is white_label
) which seemed to produce an error which suggests it 'almost' works, albiet I'd prefer not having to do a suggestion in the theme but want it in the module. I can live with it though if this works for the short/medium term:
function white_label_theme($existing, $type, $theme, $path)
{
return array(
'node__properties__full' => array(
'render element' => 'elements',
'template' => 'node--property-display--full',
'base hook' => 'node',
'path' => drupal_get_path('module', 'lrg_property_display') . '/templates',
)
);
}
This then looks for the template node--property-display--full.html.twig
but its looking in the main theme directory not in the module, even with the path specification.
The error returned was:
he website encountered an unexpected error. Please try again later.Twig_Error_Loader: Template "themes/custom/white_label/templates/nodes/node--property-display--full.html.twig" is not defined.
Reference image for comment in @Leigh's answer
node--properties--full.html.twig
. So when a viewer hits a node which is of typeproperties
I want it to use my module templatenode--property-display--full.html.twig
instead. @Kevin I am unsure, the arguments for the theme hook suggest its not by reference, see api.drupal.org/api/drupal/…node--properties--full.html.twig
in the module, too.