Sunday, March 30, 2014

How to override the menu link theme in Drupal

How to override the menu link theme

<?php
/**
* Implementation of hook_menu().
*/
function test_blockGen_menu() {
  $items['bg/testtheme'] = array(
    'title' => '',
    'page callback' => 'test_blockGen_testTheme',
    'access arguments' => array('access content'),
    'type' => MENU_CALLBACK,
  );

  return $items;
}

/**
* Implementation of hook_preprocess_page().
*/
function test_blockGen_preprocess_page(&$variables) {
  file_put_contents('/tmp/debug1', print_r($variables, TRUE) . PHP_EOL, FILE_APPEND);
}
?>

Check the debug log:

# less /tmp/debug1
Array
(
  [template_files] => Array
  (
    [0] => page-bg
    [1] => page-bg-testtheme
  )
)

Create a template file for your menu link to your default theme folder:

# echo "test test" >> /www/drupal6/sites/all/themes/mytheme/templates/page-bg-testtheme.tpl.php

Go to this link to see the result:
http://your_site.local/bg/testtheme

To feed a different template file, do:

<?php
/**
* Implementation of hook_preprocess_page().
*/
function test_blockGen_preprocess_page(&$variables) {
  $variables['template_files'][] = 'page-your-new-template';
}
?>

Reference:

Drupal 6 Template Suggestions
http://drupal.org/node/1089642

Theming nodes by content type
http://drupal.org/node/17565

Using Newer Versions of jQuery
http://drupal.org/node/1058168

Difference between hook_preprocess_page(&$variables) and phptemplate_preprocess_page(&$vars) ??
http://drupal.org/node/378872

Working with template suggestions
http://drupal.org/node/223440#custom-suggestions

Using Theme Override Functions
http://drupal.org/node/55126

No comments: