SuperRod
SuperRod

Reputation: 557

How can I use a custom template file when node_view is executed?

I am trying to integrate with a module that uses drupal_render(node_view($node)); to get a rendered node. I have a custom template file node--<type>.tpl.php that works fine when simply viewing the node, however, when the node is rendered using node_view the template file is not used, instead the core node.tpl.php in modules/node is used. I also implemented hook_preprocess_node which doesn't appear to fire in this case either.

A simple case to re-create this would be to implement hook_preprocess_node and include a watchdog message. Then execute the following in devel execute php:

$node = node_load(<nid>);
print drupal_render(node_view($node));

Any help would be greatly appreciated.

Upvotes: 1

Views: 194

Answers (1)

SuperRod
SuperRod

Reputation: 557

The issue was that at the point the other module was executing the node_view function, it was using the administrative theme rather than the public theme.

To eliminate this issue, I implemented hook_theme_registry_alter and placed the custom templates in a custom module. This way they would be used regardless of the theme selected.

Upvotes: 1

Related Questions