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 artatum on
Hello
For an effect on menu, I need to insert an attribute dynamically to all my menu links like this
going from :
<a href="xx" >Home</a>
to
<a href="xx" data-hover="Home">Home</a>
applying this pattern to each item.
Where could this be done ? (in php... On the server side without using js.)
I've tried different things...
- In page.php.tpl there is only print $content...
- MODULE_menu_link isn't the right place as there is still no html there, only node/5 for the path for instance...
where the html markup for links is added ?
Comments
theme function
You can write something like below
May this will help you !
Thanks,
Vijay Thummar
You saved my whole life !
You saved my whole life !
Thx a lot, I'll check this out !
:-)
Artatum
www.ixxi-mobility.com
Is there a way to do this
Is there a way to do this into a custom module ?
Artatum
www.ixxi-mobility.com
This is a theme override, and
This is a theme override, and as such should be done in the theme, not in a module.
Edit: by the way, two of the links in your signature are dead. They lead to 403 pages.
(thx for the warning, i'll
(thx for the warning, i'll check it out)
About my question, I found an idea here, by registering a theme function in the module :
hook_menus_theme($existing, $type, $theme, $path)
But I dont find this hook on drupal.org. And I dont know where I could find my links into those variables...
Artatum
www.ixxi-mobility.com
The hook referred to in that
The hook referred to in that post is hook_theme(). 'menus' is part of the module name.
https://api.drupal.org/api/drupal/modules%21system%21system.api.php/func...
shame on me:/
shame on me:O
thx:)
Artatum
www.ixxi-mobility.com
I cant believe we cant edit a
I cant believe we cant edit a menu link from a module !
Though I'm still rapping my head on it :/
Do you confirm othermachines ?
I 'm trying this way now:
Artatum
www.ixxi-mobility.com
another solution
I know this may be dirty solution but will help you:
Thanks,
Vijay Thummar
there is no ['links'] into
there is no ['links'] into $variable. And not id in attributes.
only $variable['attributes']['class'][0]
if ($variables['attributes']['id'] == "main-menu-links")
raise an error.
Artatum
www.ixxi-mobility.com
@artatum - There are really
@artatum - There are really no "can'ts" when it comes to customizing with Drupal, but some things are trickier than others depending on your experience/skill level. I recommend taking some time to read up on and understand Drupal hooks - theme hooks in particular. It does take a bit of effort to wrap your head around it, but once you do it makes everything so much easier. Good luck!
it's been years I read. I
it's been years I read. I bought every book, read the full web, subscribed at buildamodule and drupalize.
But I'm on this problem since days...
Sometimes you need help. A direction at least...
Everything I found speak about theme, templates, preprocessing : but I'm making a module to enhance links with graphic transitions. And I found very few things about theme ('links', ...
Artatum
www.ixxi-mobility.com
It's simply an override of
It's simply an override of the theme_links() function, and follows the same principles of all theme overrides.
What are you stuck on? I'm not clear on that.
At this time, my module only
@jaypan : I need to build a module : theme_links() is to be used in template.php ...
At this time, my module only contains the above code suggested by Vijay Thummar.
At the first call, in my debbugger $variables is like this
at the second call,
$variables['attributes']['class"]["1"] becomes "secondary-menu"
the third time it's equal to "inline"
-----------------------
1 - hence the assertion
($variables['attributes']['id']== "main-menu-links")
makes no sense...
2 - It's called 3 times as you see, and each time passing a menu and not links from these menus...
3 - I dont understand the naming of the function :/
Artatum
www.ixxi-mobility.com
theme call
It gives empty because It depends on how you call your theme function. You may not passing proper attributes in theme function.
Your function should like below
Thanks,
Vijay Thummar
Sorry I dont see where your
Sorry I dont see where your snippet goes ?
I'm using your 2 functions now ...
Artatum
www.ixxi-mobility.com
Well, it looks like
Well, it looks like AdaptiveTheme-Codex is faulty : as soon as I get back to Bartik, the $variables['links'] comes filled up with ... links.
Artatum
www.ixxi-mobility.com