Here is the proper way to drop in from link overrides for special circumstances. (In my case target="_blank")
function MY-THEME_menu_item_link($link) {
// Just an initializer
if (empty($link['localized_options'])) {
$link['localized_options'] = array();
}
// If an item is a LOCAL TASK, render it as a tab
if ($link['type'] & MENU_IS_LOCAL_TASK) {
$link['title'] = '<span class="tab">' . check_plain($link['title']) . '</span>';
$link['localized_options']['html'] = TRUE;
}
// ALTERING YOUR SPECIAL LINKS. I WAS LOOKING FOR TARGET=_BLANK
// You can also do this by checking $link['path'] with a substring, but I opted just for integer comparison for now.
if($link['mlid'] == 1210) { //http://www.tableausoftware.com/community/forums
$link['localized_options']['attributes']['target']='_blank';
}
// Proper way to return the link preserving all the extra options.
return l($link['title'], $link['href'], $link['localized_options']);
}
If you want to open ALL external links in a new window you could use $link['external'] to decide if you want to $link['localized_options']['attributes']['target']='_blank';
I did that in menu.inc and it works like a charm with just 3 extra lines of code.
For some reason the code above didn't work for me. I don't have time to check why so I've just recreated the function mixing oriol_e9g's code with theme_menu_item_link() (D6), of course inside template.php:
It sounds like the Menu attributes module (http://drupal.org/project/menu_attributes) is exactly what you are looking for, although it is only available for Drupal 6+...
Comments
I don't know of a module
I don't know of a module that does this, but you might want to take a look at these:
http://drupal.org/node/75192
http://drupal.org/node/64892
--
John Forsythe
Blamcast - Custom theme design and more...
Can't figure out a way to to
Can't figure out a way to to it at the module level, but I went for a theme level solution for now...
...however, be aware that this does not rebuild using all options that might be on the link... like fragments and queries, etc.
I was shortsighted. Here is the RIGHT WAY in D6.
Here is the proper way to drop in from link overrides for special circumstances. (In my case target="_blank")
If you want to open ALL
If you want to open ALL external links in a new window you could use $link['external'] to decide if you want to $link['localized_options']['attributes']['target']='_blank';
I did that in menu.inc and it works like a charm with just 3 extra lines of code.
My solution is a bit
My solution is a bit different. You can do something like this:
All external links have and absolute path with the "http:" sting in the url and are opened in a new page.
The internal links have a relative path without the "http:" sting in the url and are opened in the same page.
message only to thank you for
message only to thank you for this code :)
Updated function using theme_menu_item_link() D6
For some reason the code above didn't work for me. I don't have time to check why so I've just recreated the function mixing oriol_e9g's code with theme_menu_item_link() (D6), of course inside template.php:
Menu attributes module
It sounds like the Menu attributes module (http://drupal.org/project/menu_attributes) is exactly what you are looking for, although it is only available for Drupal 6+...
function themename_menu_link_
This worked for me.. !! :-)
~Swarnendu Dutta