I am not sure which part you need hardcoded, but if it is everything but the a
tag, then then l()
helper function comes to the rescue:
<li class="menu-item" id="foo">
<span>
<img src="menu_foo.png" alt="icon showing foo"/>
<?php print l("Foo", "original/path/to/foo") ?>
</span>
</li>
Now, if you access "/original/path/to/foo" or (on of its) alias(es), the l()
helper will automatically add a class "active" to the a
tag, generated by l()
.
If, for some reason you need the l()
outside of the a
, or if you want to customize the a
itself (e.g. by adding markup to it), you can use the code seen in the l()
to determine activeness of the current item. Place this as helper in template.php of your theme:
function _my_theme_is_active($path) {
$active = FALSE;
if (($path == $_GET['q'] || ($path == '<front>' && drupal_is_front_page())) &&
(empty($options['language']) || $options['language']->language == $language->language)) {
$active = TRUE;
}
return $active;
}
Obviously my_theme
is the name of your theme.
Then in the tpl.php
files, or anywhere in the scope of your theme, you can use the function:
<li>
<a href="<?php print url("original/path/to/foo") ?>" <?php print (_my_theme_is_active("original/path/to/foo") ? 'class="active"' : ' ') ?> id="foo-1">
Foo
</a>
</li>
Beware that you use url() to catch aliasing for the oringial path, but that you /do/ pass in the original (system) path into the _my_theme_is_active helper.