You need to login to send post. No account yet? Create one:
Create account

How hide node title?

1 reply [Last post]
Pete

I was hardly browse Drupal webdesign forums for that, but in node.tpl.php is not title php print. Only I found is change in page.tpl.php (if is in title variable some don't print it), but this is a little bit... not clear. Have you better hint?

admin
You have to use preprocess_page in template.php

In example in Zen theme is in your template.php (in your theme folder) section 'Override or insert variables into the page templates'. There are actually two ways to use it:

1. Simple one - only for hidding the title

  • Create content type, which shouldn't have title on webpage
  • Add this code under section 'Override or insert variables into the page templates' into your template.php file (snippet from http://drupal.org/node/426482)

function YOUR_THEME_NAME_preprocess_page(&$vars) {
  $vars['original_title'] = $vars['title'];
  if (!empty($vars['node']) && in_array($vars['node']->type, array('CONTENT_TYPE'))) {
    $vars['title'] = '';
  }
}

  • Be sure your changed YOUR_THEME_NAME by your real theme name (the name of the .info file in your theme folder)
  • Be sure your changed CONTENT_TYPE by your real machine-readable name of content type on which you want to hide title

2. Universal one

  • Choose page.tpl.php in case of content type. Add this snippet into the same section of template.php as in Simple one section (based on http://drupal.org/node/249726):

function phptemplate_preprocess(&$vars, $hook) {
  switch ($hook){
  case 'page':
  if ('node' == arg(0)) {
    $node_template = array_pop($vars['template_files']);
    $vars['template_files'][] = 'page-' . $vars['node']->type;
    $vars['template_files'][] = $node_template;
    }
    break;
  }
return $vars;
}

  • And now you can specify page-nodetype.tpl.php for any content type you want separately...