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

nevets’s picture

Using 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.

arcane’s picture

Thanks for your quick reply on this.

swentel’s picture

Status: Active » Closed (works as designed)
Wolfgang Reszel’s picture

Status: Closed (works as designed) » Active

But 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 />.

swentel’s picture

Status: Active » Closed (works as designed)

There'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()

Wolfgang Reszel’s picture

Thanks, 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?

nevets’s picture

From 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

jnettik’s picture

I 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:

$variables['short_title'] = $variables['title'];

if (!empty($variables['field_short_title'])) {
  $variables['short_title'] = $variables['field_short_title']['und'][0]['value'];
}

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?