I am using display suite to control the output of my node. I am trying to hide the node title via a preprocess function.
function mytheme_preprocess_node(&$variables) {
if ($variables['nid'] == 9) {
$variables['title'] = ""; // Hide the node title before the node is getting rendered.
}
}
I am hoping someone can tell me why the function above doesn't work. How does using display suite change preprocess functions?
Comments
Comment #1
nevets commentedUsing display suite you can control from the "Manage display" tab if the title is show or not.
If you are trying to control the title when viewing a single node (ie unaliased path of node/{nid}), the title there is controlled by page.tpl.php and hook_preprocess_page(). Note, the title variable in this case is used for more than just nodes.
Comment #2
arcane commentedThanks for your quick reply on this.
Comment #3
swentel commentedComment #4
Wolfgang Reszel commentedBut what do I have to add to my template.php if I want to alter the Title? Without Display Suite I can use mytheme_preprocess_node but with Display Suite it does not work. I would like to replace double spaces with a
<br />.Comment #5
swentel commentedThere's two options:
- on the full view mode node you can use the 'page title options' which comes in extras (as nevets says)
- or implement or hook_process_page()
Comment #6
Wolfgang Reszel commentedThanks, but this does not work on node listings like views. Is there something in Display Suite to hook into like hook_preprocess_node for normal nodes?
Comment #7
nevets commentedFrom another post on Display Suite, Field Templates may allow what you want (I haven't tried), enable the extra module that comes with DS, visit ""Structure" >> "Display Suite" >> "extras" (tab), enable "Field Templates" and see how it changes the manage display page
Comment #8
jnettikI had this same issue where I needed to display a "Short Title" field's contents in place of the $variables['title'] on select view modes. Two solutions I came up with were to create a custom DS field with hook_ds_fields_info() and place my logic in there. This needs to be done in a custom module. This ended up being my solution.
The other option I think would work would be to put the logic in template.php and create a $variables['short_title']. To give you the idea:
Then I could create a preprocess field named short_title.
IMO needing to create custom fields just to preprocess a node's title in view modes aside from full is a little heavy handed. Is there a better way to be doing this?