[gelöst] Spans zu Primary Links hinzufügen
am 03.03.2011 - 18:42 Uhr in
Hallo zusammen,
ich bin gerade kurz vorm Verzweifeln: Ich will meinen Primary Links Spans hinzufügen und kriege es nicht hin.Die Links sollen NUR in den Primary Links folgender Maßen aussehen:
<li><span class="xzy"></span><a href="">Primary Link</a><span class="abc"></span></li>Habe folgende Funktion in der template.php eingefügt:
function THEMENAME_links($links, $attributes = array('class' => 'links')) {
global $language;
$output = '';
if (count($links) > 0) {
$output = '<ul'. drupal_attributes($attributes) .'>';
$num_links = count($links);
$i = 1;
foreach ($links as $key => $link) {
$class = $key;
// Add first, last and active classes to the list of links to help out themers.
if ($i == 1) {
$class .= ' first';
}
if ($i == $num_links) {
$class .= ' last';
}
if (isset($link['href']) && ($link['href'] == $_GET['q'] || ($link['href'] == '<front>' && drupal_is_front_page()))
&& (empty($link['language']) || $link['language']->language == $language->language)) {
$class .= ' active';
}
$output .= '<li'. drupal_attributes(array('class' => $class)) .'>';
if (isset($link['href'])) {
// Pass in $link as $options, they share the same keys.
$link['html'] = TRUE;
$output .= '<span class="xyz></span>'. l($link['title'], $link['href'], $link) .'<span class="abc"></span>';
}
else if (!empty($link['title'])) {
// Some links are actually not links, but we wrap these in <span> for adding title and class attributes
if (empty($link['html'])) {
$link['title'] = check_plain($link['title']);
}
$span_attributes = '';
if (isset($link['attributes'])) {
$span_attributes = drupal_attributes($link['attributes']);
}
$output .= '<span'. $span_attributes .'>'. $link['title'] .'</span>';
}
$i++;
$output .= "</li>\n";
}
$output .= '</ul>';
}
return $output;
}Das verändert aber auch die Ausgabe von dem Sprachenwechsel-Block, den ich auf der Seite habe. Ich habe auch folgendes Snippet in die template.php gepackt:
function MYTHEME_preprocess_page(&$vars) {
$links = $vars['primary_links'];
foreach ($links as $key => $link) {
$links[$key]['html'] = true;
$links[$key]['title'] = '<span class="xyz"></span>'. $link['title'] . '<span class="abc"></span>';
}
$vars['primary_links'] = $links;
}Aber hier werden die span-Tags in den Link gepackt, ich will aber spans vor und nach dem Link-Tag haben. Kann mir da jemand helfen???
Viele Grüße,
Tobias
- Anmelden oder Registrieren um Kommentare zu schreiben

na, niemand eine Idee?
am 04.03.2011 - 15:18 Uhr
na, niemand eine Idee?
http://www.google.de/search?q
am 04.03.2011 - 15:52 Uhr
http://www.google.de/search?q=drupal+add+span+to+primary+menu
knapp 50.000 Treffer ...
Danke, ich kenne Goolge. Mit
am 04.03.2011 - 17:50 Uhr
Danke, ich kenne Goolge. Mit dieser Suche habe ich die beiden oben genannten Lösungen gefunden und aus den oben genannten Gründen passen die nicht. Ich würde hier nicht fragen, wenn ich daraus schlau werden würde.
Hallo, ich habe nun die
am 05.03.2011 - 15:08 Uhr
Hallo,
ich habe nun die Lösung von hier (http://drupalbin.com/11365) versucht, aber auch das hat nichts geändert.
Noch einmal dasProblem: ändere ich theme_links, werden alle möglichen Links verändert, z.B. auch der Sprachenwechsler. Ich brauche aber die Spans NUR in den Primary Links.
Viele Grüße,
Tobias
Ok, gelöst... dieser
am 05.03.2011 - 15:20 Uhr
Ok, gelöst... dieser Kommentar hat geholfen: http://drupal.org/node/768160#comment-3714966
Mit
if ($attributes["class"] == "links primary-links") {
}
else {
}
kann man in theme_links Definitionen nur für Primary Links festlegen.
Viele Grüße,
Tobias