Since v4 at least, Drupal couldn't handle links to named anchors in the current HTML document, e.g., a menu item "top" whose path is "#top" doesn't work properly.
I've been using a simple patch since 5.x that has worked without causing any other problems.
I can create a menu item "top" whose path is "#top" by adding the following code (line numbers are in 6.0beta3):
In common.inc, line 1230 in function 'url(...)', add line:
if(strpos($path, '#') === 0) return $path
In menu.inc, line 2152 in function 'menu_path_is_external($path)', add line:
if(strpos($path, '#') === 0) return $path;
I'm sure you could do some more checking if you want, but if it's a named anchor in the current document, I don't think anything strange after the leading '#' will cause any problems in HTML.
I hope this helps,
Mitch
Comments
Comment #1
chx CreditAttribution: chx commentedmenu_link_save
deals withoptions
already. The menu UI allows you to enter fragments. Router definitions can't use fragments but you can do amenu_link_save
.Comment #2
(not verified) CreditAttribution: commentedAutomatically closed -- issue fixed for two weeks with no activity.
Comment #3
amfis CreditAttribution: amfis commentedAnd yet.. I don't see an option in menu UI to enter anchor (fragment) nor there are explanations on how to do it.
Comment #4
amfis CreditAttribution: amfis commentedRight.. looks like I've found how to do it finally!
I need to use internal path like node/6#named_anchor to make it work.
So is it just me, or that explanation MUST be entered to a menu 'add item' UI description field?
Comment #5
sorensong CreditAttribution: sorensong commented@amfis have you been able to add simply "#1" though? For what i'm doing I need to be able to add an anchor fragment and haven't found a solution. Frustrating.
Comment #6
amfis CreditAttribution: amfis commentedYes it is :)
Your solution would look like this: l('link title', 'path', array('fragment' => '1')); And if you want to use UI, input system path not alias, like this: node/10#1
Just in case anyone wanted to know how to do it, read: http://api.drupal.org/api/drupal/includes--common.inc/function/l/6, which states, you need to look at: http://api.drupal.org/api/drupal/includes--common.inc/function/url/6 :)