Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By phsc on
Hello everybody
I tried to get <span>
tags inside the anchor tags of the primary links. In html I wanted it to look as follows:
<a href="URL"><span>link text</span></a>
Then I had a look at http://api.drupal.org/api/function/theme_links/6 and saw the following paragraph:
if (isset($link['href'])) {
// Pass in $link as $options, they share the same keys.
$output .= l($link['title'], $link['href'], $link);
}
I adjusted it to:
if (isset($link['href'])) {
// Pass in $link as $options, they share the same keys.
$output .= l('<span>' . $link['title'] . '</span>', $link['href'], $link['attributes'], $link['query'], $link['fragment'], FALSE, TRUE);
}
But all I got is that the <span>
tags were printed out as part of the title text instead of interpreted as html code. Does anybody have any idea? Every help would be very appreciated!
Thanks in advance and best regards
phs
Comments
modify page.tpl.php
Although it would be better to do it as a function, you could also go to your page.tpl.php file in the theme you are using, and add the span manually to the primary links.
HTH
Nicolas
-------------------------
http://nic.ipwa.net
Nicolas
-------------------------
Hi ipwa
Hi ipwa
Thanks for your reply, but as you already mentioned I actually want to do it as a function. ;-)
Greetings
phs
using page.tpl.php to add the span
I'm struggling with just adding the span to the page.tpl.php file.
Right now I have:
Where do I put the span to be inside the anchor tags? I realize this is a n00bish question. Maybe I'm missing something here?
If this is Drupal 6
If this is Drupal 6 add
for example:-
Setting the field html to TRUE ensures the title goes through a different filter to check_plain()
The other problem is that your adjustment of l() appears to be the Drupal 5 ways of doing things. If you are using Drupal 5 then don't be looking at the Drupal 6 API.
I will try it
Hi AjK
Thank your for your answer. I will try it after work.
And you are right, my problem appears in Drupal 6, but previously I ran it in Drupal 5 and there it worked.
Best regards
phs
Thanks! It works now!
Hi AjK
This solved my problem! Thanks!
Best regards
working example?
Hi phs are you able to paste a working example here, my php is basic and I dont know what to do with the code AJK put through.
Thanks
Hi Cocoon This is the whole
Hi Cocoon
This is the whole function (from the file "template.php") where I had to make changes. Here you can easily see where AJKs code had to be applied.
Best regards
phs
An error here maybe? ....
Phs,
you've made a slight error here I think. In wanting to wrap your links in a span I was expecting the link title to be passed in as html and therefore the caller sets $link['html'] == TRUE in which case it's the callers responsibilty to do output filtering. However, I see you are actually overriding the theme_links() function in your theme layer. So, your code thus:-
really should be done thus:-
Notice the addition of the check_plain() function around the $link['title'] outside of the additional span html you placed in there?
The reason for that is by calling l() with the html flag true by passes it's internal security step of doing a check_plain() for you.
Why is it needed. Well, if you know the origin of every piece of text that will make a link title then it doesn't matter. But if you have any chance that untrusted user input could leak into a link title, you must close the potential XSS security hole1. And that means making sure untrusted user input is sanitized on output.
Further reading 1
span with no function
Hi,
I need receive something like that:
How can I insert without calling function:
Could you clean up my code:
Kind ragars,
Adrian
Hi, I have made chandes
Hi, I have made chandes in:
1. page.tpl.php
print theme('links', $primary_links, array('class' => 'links primary-links'))
endif;
?>
2. template.php
but span tags are missing:
I want receive:
Hi All, Fantastic work. I
Hi All,
Fantastic work. I am having trouble following some of this though, specifically where the code should be going. I thought I had it, tried it, but nothing. Is there any chance of someone posting sample file(s) for this, that way I can compare excatly what I am doing and where.
Cheers,
Nick
----------------------------------
Nick Young
www.nickbits.co.uk
------------oOo----------------------
Nick Young (www.nickbits.co.uk)
drupal links with "|"delimiter
HOw can I change this code to get the "|"delimiter in the primary links
http://api.drupal.org/api/function/theme_links/6
??
in drupal 4.7 it was just one line of code>>
:-)
Http://www.reloadmedia.com
Http://www.reloadmedia.com
Thanks So much
Thanks So much
Thank you
Thanks for the clear explanation on this.
Hi Thanks for this - it's
Hi
Thanks for this - it's working for me on D6. Although, it's only working for my Primary Links, not any other menu block. Is there any way to make this work on all Drupal menus (Navigation, etc)?
Many thanks
Dan
Ironic
How ironic. I have some other, very similar code I obtained from a blog but it is not just putting the span tags around the titles of my primary links, but also killing the image-based links that two contrib modules I'm using have created... all I am trying to do is figure out how to restrict the effect to my primary menu! :)
Getting SPAN in menu links in D6
You can insert span tags on menu links by placing the following code in your themes template.php file.
Remember to change "mytheme" to the name of your theme.
Note: The line
$link['localized_options'] += array('html'=> TRUE);
adds the html field to the options array and sets it to TRUE.If you use this method it
If you use this method it won't work with the DHTML Menus Module because it won't hit theme_menu_item_link. In my case I didn't need DHTML Menus on the menu I was adding the span to so I turned it off.
Edit your template.php file
Edit your template.php file and use the preprocess_page function in D6.
Change "YOURTHEME" with the name of your theme and that's all.
Tried it.
i have the same issue, and have spent two days on it :P
Can't figure anything out. It actually seems like my template.php isn't being recognized, because nothing i do to it (aside from improper code - like, the kind that throws errors) is recognized!
i've built the theme in question from scratch, and it's pretty bare-bones. Is there some type of code i need to put somewhere to get my template.php recognized?
Cache
You've tried clearing your theme registry?
(This solution is also not working for me - no "span" tags appearing.)
-- If no-one asked Drupal questions there would be no Drupal answers --
Some Help
In drupal 6, i need only to change template.php with this code?
I didn't make it work, have i missed something?
thanks!
Superfish
If you're using Superfish, use theme_superfish_menu_item_link() instead of theme_menu_link().
See: http://stackoverflow.com/questions/13477629/how-to-add-a-span-tag-to-a-c...