1

How do I override the template of a node based on where it is in the menu?

For example, I create a node, and within the "Menu settings" I put it under some "parent item". I wish to use a specific template for nodes of a particular content type that fall under a particular parent item.

0

I believe it is possible to achieve this in hook_preprocess_node by calling menu_get_item, checking whether it is the item you are looking for (checking the parent etc.) and then assigning the appropriate template like this: $vars['template_file'] = 'your_template_file';

  • I was unsuccessful in getting the menu parent item by simply calling menu_get_item. There appeared to be no information gotten regarding menu items. I've managed to figure it out however. I'll post the answer. – KyoreG Feb 5 '14 at 14:49
0

I figured it out by doing something like this in theme_preprocess_page

$link_path = "node/$node->nid";
$result = db_query('SELECT m.plid from {menu_links} m where m.link_path = :lpath', array(':lpath' => $link_path));

where plid, the parent menu id, is what I needed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.