how do I make spand id unique in function l()
neeshpal - November 10, 2009 - 22:43
Hello,
I changed function l() in common.inc from.
return '<a href="'. check_url(url($path, $options)) .'"'. drupal_attributes($options['attributes']) .'>'. ($options['html'] ? $text : check_plain($text)) .'</a>';to
return '<a href="'. check_url(url($path, $options)) .'"'. drupal_attributes($options['attributes']) .'><span id = "whatever" >'. ($options['html'] ? $text : check_plain($text)) .'</a>';to look my output like this
<a title="" href="http://cnn.com">
<span id="whatever">News</span>
</a>but how do I make the span ID unique for each <a> tag. Right now the value is "whatever" for all the <a> tags in the menu. I use D6

does someone has any idea
does someone has any idea about this?
You really shouldn't be
You really shouldn't be modifying the core files. Check the handbook for overriding functions.
With your second question, view the Drupal API on the l() function (http://api.drupal.org/api/function/l). You should be able to pass an ID inside attributes array, which resides in the $options array.
Without knowing how you're assembling those links, I can't help you with the unique part. Normally I'd use something quick and dirty like
<?php
print l($node->title,
'node/'.$node->nid,
array(
'attributes' => array(
'class' => 'link',
'id' => 'link-'.$node->nid,
)
)
);
?>
.. to generate a unique link using the node id. Or override a list function to provide nice css ID's
Thanks a lot for your
Thanks a lot for your reply.
I could follow what you were saying but I couldnt know how to populate $node->nid (because of array within array and my limited knowledge in PHP). Then I thought of populating $node->nid directly in function l() like this ( I used two method that I came across from different forums. I am listing both of them)
function l($text, $path, $options = array()) {
// *********HERE*************
drupal_get_normal_path($path);
if (arg(0) == 'node' && is_numeric(arg(1))) {
$node = node_load(arg(1));
}
//**************************
// Merge in defaults.
$options += array(
'attributes' => array(),
'html' => FALSE,
);
// Append active class.
if ($path == $_GET['q'] || ($path == '<front>' && drupal_is_front_page())) {
if (isset($options['attributes']['class'])) {
$options['attributes']['class'] .= ' active';
}
else {
$options['attributes']['class'] = 'active';
}
}
// Remove all HTML and PHP tags from a tooltip. For best performance, we act only
// if a quick strpos() pre-check gave a suspicion (because strip_tags() is expensive).
if (isset($options['attributes']['title']) && strpos($options['attributes']['title'], '<') !== FALSE) {
$options['attributes']['title'] = strip_tags($options['attributes']['title']);
}
//*******POPULATING HERE********************
return '<a href="'. check_url(url($path, $options)) .'"'. drupal_attributes($options['attributes']) .'>'.'<span id ='.$node->nid .'>'. ($options['html'] ? $text : check_plain($text)) .'</a>';
}
and
//Assume these two lines of code to be on the same place as above and populating same as above.
drupal_get_normal_path($path);
$node = node_load($nid);
I also tried these two method in theme_menu_item (because it calls function l() ) and passing $node like this
function theme_menu_item_link($link,$path) {
//********THIS*****
drupal_get_normal_path($path);
$node = node_load($nid);
print $node->nid;
//****OR THIS******
drupal_get_normal_path($path);
if (arg(0) == 'node' && is_numeric(arg(1))) {
$node = node_load(arg(1));
}
if (empty($link['localized_options'])) {
$link['localized_options'] = array();
}
return l($link['title'], $link['href'], $link['localized_options'], $node);
}
The problem is that node object doesn't get loaded anywhere. Any help would be appreciated.