La adición de Drupal Span dentro de un tag en Niza Menús
Pregunta
Estoy tratando de añadir menús desplegables para un tema de Drupal que utiliza el texto deslizante redondeo puerta CSS.
La versión actual utiliza una inyección de enlaces primaria del tramo en las etiquetas A, que funciona muy bien. Pero no soporta menús desplegables.
Código de trabajo:
<?php print theme('links', $primary_links, array('class' => 'links primary-links')) ?>
En la plantilla con una adición de archivos template.php:
<?php
// function for injecting spans inside anchors which we need for the theme's rounded corner background images
function strands_guybrush_links($links, $attributes = array('class' => 'links')) {
$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()))) {
$class .= ' active';
}
$output .= '<li'. drupal_attributes(array('class' => $class)) .'>';
if (isset($link['href'])) {
$link['title'] = '<span class="link">' . check_plain($link['title']) . '</span>';
$link['html'] = TRUE;
// Pass in $link as $options, they share the same keys.
$output .= l($link['title'], $link['href'], $link);
}
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;
}
?>
Solución
Si desea envolver las etiquetas unas con un palmo, puede sobrescribir la theme_nice_menu_build
y añadir su período a la salida. Si desea dentro de la una etiqueta que necesita para sobrescribir el menu_item_link
.
Se puede escribir sobre un tema Funciton por la creación de una llamada a la función your_theme_name_function_name
y Drupal va a utilizar esa función para hacer que el margen de beneficio en lugar de la que viene por defecto. De esa manera usted puede alterar el marcado de la forma que desee. Esta función debe estar en el archivo template.php de su tema.
Una buena manera de empezar es copiar la función que desea sobrescribir y modificar únicamente a sus gustos.
Mucho ha sucedido desde Drupal 4.7, no espero que se utiliza. Es bastante fácil de insertar etiquetas span:
function your_theme_name_menu_item_link($link) {
if (empty($link['localized_options'])) {
$link['localized_options'] = array();
}
$link['localized_options']['html'] = TRUE;
return l('<span>' . $link['title'] . '</span>', $link['href'], $link['localized_options']);
}
He probado esto y funciona muy bien.