Understand variables - Overriding theme_menu_item

neeshpal - November 2, 2009 - 20:20

Hi All,
I've just started learning theme development and came to know that all of it is developed by drupal variables , html, css and php. I came across list of variables here http://drupal.org/node/11812 , but i think these are not all the variables that are used by drupal. So where can I get more information on all the available variables and how those variables relates to the development from the front end i.e. from the /admin/build/theme page or any other such page.

Thank You.

_

WorldFallz - November 2, 2009 - 21:47

The available variables depend on what context you're talking about (ie node, page, view, etc) as well as what modules you have installed. The updated version of the page you linked is http://api.drupal.org/api/drupal/modules--system--page.tpl.php (and the corresponding node version is http://api.drupal.org/api/drupal/modules--node--node.tpl.php).

However, since modules and themes can add variables your best bet is to use something like this to see what's available:

<?php
print '<pre>';
print_r(array_keys(get_defined_vars()))
print
'</pre>';
?>

If you use the devel module, you can use dsm(get_defined_vars()); to get a much nicer listing.

_
Don't be a Help Vampire - read and abide the forum guidelines.
If you find my assistance useful, please pay it forward to your fellow drupalers.

Outdated

yelvington - November 2, 2009 - 22:04

You're looking at documentation for Drupal 5. Much has changed.

Read the Drupal 6 Theme Developer Guide, any current (D6) book on Drupal theme development, and/or the documentation for any core default template file, such as:

http://api.drupal.org/api/drupal/modules--system--page.tpl.php/6
http://api.drupal.org/api/drupal/modules--node--node.tpl.php/6
etc

Note that different variables are available to different templates.

Many thanks

neeshpal - November 4, 2009 - 16:43

Thank You all for replying.
Within last 1-2 days since i wrote this post , with the help of above info and the forum info , i've been able to understand the basics of theme development. I created regions with HTML and css for my site. I am struggling in understanding any further like how does the HTML of a menu is produced and how do we customize it for one's specific need. If I am not wrong , it has to do something with hook menu. Any pointers that would help me understand the HTML system of menus will be greatly appreciated.

Thank You again!!

_

WorldFallz - November 4, 2009 - 18:51

http://api.drupal.org/api/function/hook_menu defines menu items and callbacks-- not html.

html is usually taken care of via theming-- either with template files (*.tpl.php) or with theme functions. Menus that appear in blocks are also affected by block.tpl.php files.

_
Don't be a Help Vampire - read and abide the forum guidelines.
If you find my assistance useful, please pay it forward to your fellow drupalers.

Override theme_menu_item how to proceed

neeshpal - November 5, 2009 - 17:26

Thank You all for pointing me to the right direction . After some search I came across this piece of code to override theme_menu_item and to generate custom ID and classes but I couldnt understand

1.when I put this function in template.php, site gives me an error. I am trying this for zen theme.
"Call to undefined function menu_item_link() in /home/inventi1/public_html/themes/zen/zen/template.php on line 296"

2. how do we use those generated ID's and classes. Do we've to use CSS (our standard style.css file)?

I got it from here:

http://www.nerdliness.com/article/2008/01/01/power-template-php

Can someone please help me with the above.

/**
* Implementation of theme_menu_item().
*
* Add active class and custom id to current menu item links.
*/

function phptemplate_menu_item($mid, $children = '', $leaf = TRUE) {
  $item = menu_get_item($mid); // get current menu item

  // decide whether to add the active class to this menu item
  if ((drupal_get_normal_path($item['path']) == $_GET['q']) // if menu item path...
  || (drupal_is_front_page() && $item['path'] == '<front>')) { // or front page...
    $active_class = ' active'; // set active class
  } else { // otherwise...
    $active_class = ''; // do nothing
  }

  $attribs = isset($item['description']) ?
array('title' => $item['description']) : array();
  $replace = array(' ', '&');
  $attribs['id'] = 'menu-'. str_replace($replace, '-', strtolower($item['title']));

  return
'<li class="'. ($leaf ? 'leaf' : ($children ? 'expanded' : 'collapsed')) .
$active_class .'" id="'. $attribs['id'] . '">' .
menu_item_link($mid) . $children ."</li>\n";
}

can someone help in the

neeshpal - November 6, 2009 - 17:50

can someone help in the above? thanks..

did you try google for this

apilasiewicz - November 10, 2009 - 14:21
 
 

Drupal is a registered trademark of Dries Buytaert.