This is in response to http://drupal.org/node/61713
I'm placing my response here to open up discussion.
Documentation for the Smarty theme-engine is lacking -- in some ways this is appropriate as it mirrors the functionality of phptemplate in many ways but this leads to confusion. Between work and classes I haven't had time to write much doc -- I'm more than willing to accept submissions from anyone and will be sitting down to write more comprehensive documentation soon.
--------------------------------
To do custom theming of that (or any themable) function you'll need an entry in the smartytemplate.php file residing within the theme's directory.
If you'd like to do rendering with smarty as opposed to having your rendering logic in straight php within smartytemplate.php you can call _smarty_callback*() with the appropriate parameters and create a corresponding .tpl file.
/**
* Catch the theme_item_list function, and redirect through the template api
*/
function smarty_item_list($items = array(), $title = NULL) {
// Pass to phptemplate, including translating the parameters to an associative array. The element names are the names that the variables
// will be assigned within your template.
return _smarty_callback('item_list', array('items' => $items, 'title' => $title));
}
This example would allow you to then make a item_list.tpl file within the theme directory and do the rendering there.
I'm not sure what you're aiming for but as theme_menu_tree is a very light wrapper for the results of menu_tree the easiest path is probably combing the logic of the two into a smarty_menu_tree function within smartytemplate.php. (Alternatively, you can name it (theme_name)_menu_tree).
Both of these functions are so light in markup you'll likely not want to hand off rendering to smarty (with the _smarty_callback).
To take this path you would find the vanilla code for the functions (theme_menu_tree, menu_tree). They reside in menu.inc or you could grab it from the api site:
http://api.drupal.org/api/HEAD/function/theme_menu_tree
http://api.drupal.org/api/HEAD/function/menu_tree
You then combine the two within your smartytemplate.php file as smarty_menu_tree to get something like this:
function smarty_menu_tree($pid = 1) {
$menu = menu_get_menu();
$output = '';
if (isset($menu['visible'][$pid]) && $menu['visible'][$pid]['children']) {
foreach ($menu['visible'][$pid]['children'] as $mid) {
$type = isset($menu['visible'][$mid]['type']) ? $menu['visible'][$mid]['type'] : NULL;
$children = isset($menu['visible'][$mid]['children']) ? $menu['visible'][$mid]['children'] : NULL;
$output .= theme('menu_item', $mid, menu_in_active_trail($mid) || ($type & MENU_EXPANDED) ? theme('menu_tree', $mid) : '', count($children) == 0);
}
}
if ($output) {
return "\n<ul class=\"menu\">\n". $output ."\n</ul>\n";
}
}
Which you can then start modifying as you see fit.
tclineks
Comments
Thanks a ton for this reply.
Thanks a ton for this reply. As I get more familiar with Smarty and how the engine is integrated into Drupal, I'll gladly return some documentation for it. Off to learning it :)
Thanks again.