Drupal development
zero dev header imagezero dev header imagezero dev header imagezero dev header image

Drupal: Remove title and breadcrumb from front page

zero dev's picture

When you have a panel or a front page design that does not require a breadcrumb or a title you can either use CSS or Drupal's template_preprocess_page function

By overriding elements of it in template.php in your theme folder you can alter the defaults and change a number of things. It looks like this:

<?php
function template_preprocess_page(&$variables) {
 
// Add favicon
 
if (theme_get_setting('toggle_favicon')) {
   
drupal_set_html_head('<link rel="shortcut icon" href="'. check_url(theme_get_setting('favicon')) .'" type="image/x-icon" />');
  }

  global
$theme;
 
// Populate all block regions.
 
$regions = system_region_list($theme);
 
// Load all region content assigned via blocks.
 
foreach (array_keys($regions) as $region) {
   
// Prevent left and right regions from rendering blocks when 'show_blocks' == FALSE.
   
if (!(!$variables['show_blocks'] && ($region == 'left' || $region == 'right'))) {
     
$blocks = theme('blocks', $region);
    }
    else {
     
$blocks = '';
    }
   
// Assign region to a region variable.
   
isset($variables[$region]) ? $variables[$region] .= $blocks : $variables[$region] = $blocks;
  }

 
// Set up layout variable.
 
$variables['layout'] = 'none';
  if (!empty(
$variables['left'])) {
   
$variables['layout'] = 'left';
  }
  if (!empty(
$variables['right'])) {
   
$variables['layout'] = ($variables['layout'] == 'left') ? 'both' : 'right';
  }

 
// Set mission when viewing the frontpage.
 
if (drupal_is_front_page()) {
   
$mission = filter_xss_admin(theme_get_setting('mission'));
  }

 
// Construct page title
 
if (drupal_get_title()) {
   
$head_title = array(strip_tags(drupal_get_title()), variable_get('site_name', 'Drupal'));
  }
  else {
   
$head_title = array(variable_get('site_name', 'Drupal'));
    if (
variable_get('site_slogan', '')) {
     
$head_title[] = variable_get('site_slogan', '');
    }
  }
 
$variables['head_title']        = implode(' | ', $head_title);
 
$variables['base_path']         = base_path();
 
$variables['front_page']        = url();
 
$variables['breadcrumb']        = theme('breadcrumb', drupal_get_breadcrumb());
 
$variables['feed_icons']        = drupal_get_feeds();
 
$variables['footer_message']    = filter_xss_admin(variable_get('site_footer', FALSE));
 
$variables['head']              = drupal_get_html_head();
 
$variables['help']              = theme('help');
 
$variables['language']          = $GLOBALS['language'];
 
$variables['language']->dir     = $GLOBALS['language']->direction ? 'rtl' : 'ltr';
 
$variables['logo']              = theme_get_setting('logo');
 
$variables['messages']          = $variables['show_messages'] ? theme('status_messages') : '';
 
$variables['mission']           = isset($mission) ? $mission : '';
 
$variables['primary_links']     = theme_get_setting('toggle_primary_links') ? menu_primary_links() : array();
 
$variables['secondary_links']   = theme_get_setting('toggle_secondary_links') ? menu_secondary_links() : array();
 
$variables['search_box']        = (theme_get_setting('toggle_search') ? drupal_get_form('search_theme_form') : '');
 
$variables['site_name']         = (theme_get_setting('toggle_name') ? filter_xss_admin(variable_get('site_name', 'Drupal')) : '');
 
$variables['site_slogan']       = (theme_get_setting('toggle_slogan') ? filter_xss_admin(variable_get('site_slogan', '')) : '');
 
$variables['css']               = drupal_add_css();
 
$variables['styles']            = drupal_get_css();
 
$variables['scripts']           = drupal_get_js();
 
$variables['tabs']              = theme('menu_local_tasks');
 
$variables['title']             = drupal_get_title();
 
// Closure should be filled last.
 
$variables['closure']           = theme('closure');

  if (
$node = menu_get_object()) {
   
$variables['node'] = $node;
  }

 
// Compile a list of classes that are going to be applied to the body element.
  // This allows advanced theming based on context (home page, node of certain type, etc.).
 
$body_classes = array();
 
// Add a class that tells us whether we're on the front page or not.
 
$body_classes[] = $variables['is_front'] ? 'front' : 'not-front';
 
// Add a class that tells us whether the page is viewed by an authenticated user or not.
 
$body_classes[] = $variables['logged_in'] ? 'logged-in' : 'not-logged-in';
 
// Add arg(0) to make it possible to theme the page depending on the current page
  // type (e.g. node, admin, user, etc.). To avoid illegal characters in the class,
  // we're removing everything disallowed. We are not using 'a-z' as that might leave
  // in certain international characters (e.g. German umlauts).
 
$body_classes[] = preg_replace('![^abcdefghijklmnopqrstuvwxyz0-9-_]+!s', '', 'page-'. form_clean_id(drupal_strtolower(arg(0))));
 
// If on an individual node page, add the node type.
 
if (isset($variables['node']) && $variables['node']->type) {
   
$body_classes[] = 'node-type-'. form_clean_id($variables['node']->type);
  }
 
// Add information about the number of sidebars.
 
if ($variables['layout'] == 'both') {
   
$body_classes[] = 'two-sidebars';
  }
  elseif (
$variables['layout'] == 'none') {
   
$body_classes[] = 'no-sidebars';
  }
  else {
   
$body_classes[] = 'one-sidebar sidebar-'. $variables['layout'];
  }
 
// Implode with spaces.
 
$variables['body_classes'] = implode(' ', $body_classes);

 
// Build a list of suggested template files in order of specificity. One
  // suggestion is made for every element of the current path, though
  // numeric elements are not carried to subsequent suggestions. For example,
  // <a href="http://www.example.com/node/1/edit" title="http://www.example.com/node/1/edit">http://www.example.com/node/1/edit</a> would result in the following
  // suggestions:
  //
  // page-node-edit.tpl.php
  // page-node-1.tpl.php
  // page-node.tpl.php
  // page.tpl.php
 
$i = 0;
 
$suggestion = 'page';
 
$suggestions = array();
  while (
$arg = arg($i++)) {
   
$arg = str_replace(array("/", "\\", "\0"), '', $arg);
   
$suggestions[] = $suggestion .'-'. $arg;
    if (!
is_numeric($arg)) {
     
$suggestion .= '-'. $arg;
    }
  }
  if (
drupal_is_front_page()) {
   
$suggestions[] = 'page-front';
  }

  if (
$suggestions) {
   
$variables['template_files'] = $suggestions;
  }
}
?>

The first thing you want to do it change the name of the function, otherwise you will get an error for declaring the function twice. Change the name to phptemplate_preprocess_page or replace 'template' with your theme name.

Then we can make some changes. Half way through you can see a big chunk where the main page variables are set, see http://api.drupal.org/api/drupal/modules--system--page.tpl.php/6 for more information about them.

You can see from the function it's easy to check for whether we're on the front page - there are a couple of places where that happens. So, all we need to do is check for front page and override some variables - it'll look something like this:

<?php
function template_preprocess_page(&$variables) {
 
//If front page remove title and breadcrumb
 
if (drupal_is_front_page()) {
   
$variables['breadcrumb'] = '';
   
$variables['title'] = '';
  }
}
?>

The final stage is to clear the cache (bottom of the performance page) so that Drupal will register our changes and hey presto done!

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.

©2010 zero-dev

Powered by Drupal, an open source content management system