Posted by jgavin on June 9, 2006 at 1:17am
Heys everyone, i installed Drupal 4.7.2 and im in the process of coding (or trying to) my theme. And after moving php code all around i came to this conclusion:
1. This
<?php
print $tabs
?>prints this:
2.
<ul class="tabs primary">
<li><a href="/?q=user/1">view</a></li>
<li class="active"><a href="/?q=user/1/edit" class="active">edit</a></li>
<li><a href="/?q=user/1/track">track</a></li>
<li><a href="/?q=user/1/contact">contact</a></li>
</ul>
<ul
class="tabs secondary">
<li class="active"><a href="/?q=user/1/edit" class="active">account settings</a></li>
<li><a href="/?q=user/1/edit/optional+information">optional information</a></li>
<li><a href="/?q=user/1/edit/personal+information">personal information</a></li>
<li><a href="/?q=user/1/edit/work">work</a></li>
</ul>I need it to print this:
<ul class="tabs primary">
<li><a href="/?q=user/1"><span class="a"><span class="b">view</span></span></a></li>
<li class="active"><a href="/?q=user/1/edit" class="active"><span class="a"><span class="b">edit</span></span></a></li>
<li><a href="/?q=user/1/track"><span class="a"><span class="b">track</span></span></a></li>
<li><a href="/?q=user/1/contact"><span class="a"><span class="b">contact</span></span></a></li>
</ul>
<ul class="tabs secondary">
<li class="active"><a href="/?q=user/1/edit" class="active"><span class="a"><span class="b">account settings</span></span></a></li>
<li><a href="/?q=user/1/edit/optional+information"><span class="a"><span class="b">optional information</span></span></a></li>
<li><a href="/?q=user/1/edit/personal+information"><span class="a"><span class="b">personal
information</span></span></a></li>
<li><a href="/?q=user/1/edit/work"><span class="a"><span class="b">work</span></span></a></li>
</ul>Pretty much all i need is the stupid <span>'s to be put in. I have been moving code around with no luck. Can anyone help?
[fixed tags]
Comments
Why not edit your style.css
Why not edit your style.css file to something of this nature:
.tabs_primary {
/* edit style here */
}
.tabs_primary a:link {
/* put style elements from your class b here */
}
You'll have to edit your includes/menu.inc file to change "tabs primary" to "tabs_primary" in the theme_menu_local_tasks() function.
---
Redbox Codes
Michael Scott from The Office
Brangelina
...My Dupral Implementations
---
Redbox Codes
Michael Scott
^- Some of my Dupral Implementations
I wouldn't recommend editing menu.inc
Instead override either or both of the following functions in your theme:
http://api.drupal.org/api/4.7/function/theme_menu_local_tasks
http://api.drupal.org/api/4.7/function/theme_menu_local_task
more info:
http://drupal.org/node/55126
http://drupal.org/node/11811
--
Anton
New to Drupal? | Forum posting tips | Troubleshooting FAQ
Example Knowledge Base built using Drupal
--
Anton
How do i override it?
Thanks for those links, OK, im begining to understand a LITTLE of what Overrides do. Im still a little confused on how to set it up though. I dont have a template.tpl file so i dont know how to create and use that. If you have the time, could you please show me step by step on how to override the menus to get the above result i am looking for. I dont know to what extent of time it would take to do this, but anymore help would be greatly appreciated. Thanks!
--
Drupal is Awesome
template.php
If your theme doesn't have a template.php file, it didn't previously need one. You can just create a blank file called template.php and stick your override functions in it.
eg: here is the vanilla theme function for outputting a menu item:
http://api.drupal.org/api/4.7/function/theme_menu_local_task
function theme_menu_local_task($mid, $active, $primary) {if ($active) {
return '<li class="active">'. menu_item_link($mid) ."</li>\n";
}
else {
return '<li>'. menu_item_link($mid) ."</li>\n";
}
}
Create a template.php file in your theme directory, then add a function like the following into it:
function phptemplate_menu_local_task($mid, $active, $primary) {if ($active) {
return '<li class="active"><span class="a"><span class="b">'. menu_item_link($mid) ."</span></span></li>\n";
}
else {
return '<li><span class="a"><span class="b">'. menu_item_link($mid) ."</span></span></li>\n";
}
}
Notice the new function name and the new spans added to the output.
This is the basic way of overriding a theme function. It doesn't use the callbacks or stubs etc.
Using a theme override means that your menu.inc file hasn't been edited, so your changes won't need to be merged back into any future versions of menu.inc that come out. This is why you shouldn't edit core files - they make future patching and upgrading much harder.
--
Anton
New to Drupal? | Forum posting tips | Troubleshooting FAQ
Example Knowledge Base built using Drupal
--
Anton
getting closer...OK so i
getting closer...OK so i created the template.php and put the function in and it still didnt work but the span's were put in. Although before the href. I created a html test file, put the span's after the href, uploaded it and it worked. So this means i have to put after the href.
I did what you said and the page sources looks like this:
<li><span class="a"><span class="b"><a href="/?q=user/1/subscriptions/taxa">categories</a></span></span></li>I need it to look like this:
<li><a href="/?q=user/1/subscriptions/taxa"><span class="a"><span class="b">categories</span></span></a></li>again, thanks for your help!
--
Drupal is Awesome
OK I didn't look closely enough at your HTML
But just follow the same procedure...
In http://api.drupal.org/api/4.7/function/theme_menu_local_task, the bit that creates the link is:
return '<li>'. menu_item_link($mid) ."</li>\n";So looking at the docs for menu_item_link (http://api.drupal.org/api/4.7/function/menu_item_link), you see this:
return theme('menu_item_link', $item, $link_item);Following the docs to http://api.drupal.org/api/4.7/function/theme for the theme function, you can see that it is ultimately calling the
theme_menu_item_link()function to output the HTML.Looking up http://api.drupal.org/api/4.7/function/theme_menu_item_link gives us this code:
return l($item['title'], $link_item['path'], isset($item['description']) ? array('title' => $item['description']) : array());Which uses the l() (http://api.drupal.org/api/4.7/function/l) function to create a link based on a title, a path and bunch of other stuff.
What you could do is add your span elements to the title text of the link. Note: from the l() documentation, you will also need to set the $HTML parameter as TRUE to include span elements in there.
To do this, override the theme_menu_item_link() function in your template.php from this:
<?phpfunction theme_menu_item_link($item, $link_item) {
return l($item['title'], $link_item['path'], isset($item['description']) ? array('title' => $item['description']) : array());
}
?>
to something like this:
<?phpfunction theme_menu_item_link($item, $link_item) {
$link_text = '<span class="a"><span class="b">' . $item['title'] . '</span></span>';
return l($link_text, $link_item['path'], isset($item['description']) ? array('title' => $item['description']) : array(), NULL, NULL, FALSE, TRUE);
}
?>
The , NULL, NULL, FALSE, TRUE bit added to the end of the l() function call was just to get that $HTML= TRUE bit for the last parameter. Otherwise, the angle brackets in your span additions would be escaped to their HTML entities.
Note: I haven't tested whether all this actually works or not.
--
Anton
New to Drupal? | Forum posting tips | Troubleshooting FAQ
Example Knowledge Base built using Drupal
--
Anton
Yes and No...
So i pasted:
<?phpfunction theme_menu_item_link($item, $link_item) {
$link_text = '<span class="a"><span class="b">' . $item['title'] . '</span></span>';
return l($link_text, $link_item['path'], isset($item['description']) ? array('title' => $item['description']) : array(), NULL, NULL, FALSE, TRUE);
}
?>
and got this when i go to the page online:
Fatal error: Cannot redeclare theme_menu_item_link() (previously declared in /home/example/public_html/includes/menu.inc:697) in /home/example/public_html/themes/custom/template.php on line 5
BUT... when i paste the above code into the menu.inc (just to see what happens) then it worked! On one hand im happy that it works on the other im still confused why the template.php didnt override it? Any suggestions?
-thanks
--
Drupal is Awesome
Rename the function definition
Like with the first override example:
theme_menu_item_link() should be phptemplate_menu_item_link()
More explanation: http://drupal.org/node/55126 (same link as earlier)
I could say I was testing you, but I just forgot to change that bit of the code I pasted in :)
--
Anton
New to Drupal? | Forum posting tips | Troubleshooting FAQ
Example Knowledge Base built using Drupal
--
Anton
BINGO!!
that was it! thanks again for all your help.
--
Drupal is Awesome