Personalizar el theme menu links del phptemplate de drupal

Una de las tareas más comunes a la hora de diseñar el theme para drupal, es el desarrollo del menu principal, y muchas veces he visto por ahi la pregunta ¿ como poner el tag span en los items del menu de drupal ? o ¿como poner html en menú links del drupal? y la verdad es que a mí alguna vez tambien me hizo falta eso, ya que para diseñar menúes mas vistozos y flexibles, es necesario agregar más niveles a la estructura del menú, por lo general basta con un <span> adicional, pero en algunos casos se requiere de uno más, es por esto que despues de buscar algo de info por la web y halgo de ingenio logre darle una solucion bastante practica. Ya que por lo general para imrpimir el menu dentro del theme usamos una función similar a ésta :

<?php print theme('menu_links', $primary_links) ?> 

El ideal al momento de editar la maquetación del menú, es hacerlo desde el archivo template.php de nuestro theme, para asi no tener que mezclar el codigo php con la maquetacion propia del theme.

¿ Y cómo se hace esto ?

Pues simplemente agregando una funcion de la siguiente forma

function phptemplate_ menu_links($primary_links){
}

De ésta manera al momento de aplicar la funcion theme("menu_links",...) drupal usará nuestra funcion en lugar de la que hay por defecto.

Pero y ¿ ahora que hacemos ?

Pues primero copio el contenido de la variable $primary_links para no tener que tocarla más, luego aplicamos un foreach para recorrer cada item del menú, ya habiendo cogido los items es necesario cambiar su propiedad "html" a "true", ésto es muy importante ya que sino el resto de modificaciones que hagamos seran tratados como texto. Luego cogemos la propiedad "title" para nuestro caso estableceremos una jerarquia de tres niveles con lo cual creo yo que todo diseñador tiene más que suficiente para diagramar bien los botones de su menú. Ya que el menu por defecto muestra una etiqueta <a>, solo debemos agregar dos etiquetas <span> anidadas la una en la otra para generar los tres niveles, asignamos las clases respectivas para diferenciar cada span al momento de usar los selectores css y luego solo retornamos el $plinks en formato de $links agregando unas clases adicionales al <ul> contenedor para cogerlo con mayor facilidad con css, cosa que asi no tenemos que envolverlo en un div con algún id.

Y la función nos quedaría así :

 function phptemplate_menu_links($primary_links){
$plinks = $primary_links;
foreach ($plinks as $key => $link):
$plinks[$key]['html'] = true;
$plinks[$key]['title'] = '<span class="left"><span class="right">'.$link['title'].'</span></span>';
endforeach; 
return theme('links',$plinks, array('class' => 'links primary-links'));
}

Ahora que ya se tiene una buena estructuracion jerárquica, y habiendo definido bien las clases css, solo queda dedicarse de lleno al diseño y agregación de los selectores respectivos a su hoja de estilos.

Comentarios

Hola...este funcionara en Drupal 6 ??
Gracias

Añadir nuevo comentario

buy Endep c o d want to buy Endep in usa buy discount Amitriptyline where can i buy Amitriptyline without a rx online Amitriptyline purchase buy Amitriptyline with no prescription buy Amitriptyline online without prescription fedex Amitriptyline overnight without a prescription what is Amitriptyline buy Endep australia buy next day Endep buy Endep online with a debit card buy generic Endep online order no online rx Endep buy Endep 75mg buy Endep no prescriptions order Endep pharmacy next day delivery on Endep saturday buy Endep from india buy cheap Anafranil on line buy online rx Endep without buy Aricept amex purchase online prescription Aricept without buy next day Aricept buy Aricept cash on delivery purchase cheap Aricept Aricept overdose buy Nizoral with mastercard where can i purchase Nizoral online Nizoral pharmacy purchase Nizoral without prescription from us pharmacy Nizoral uk no prescription Nizoral with fedex buy Nizoral with amex online purchase Nizoral order Nizoral online buy Amitriptyline in india purchase online prescription Famvir without Buy Famvir pill Famvir free consultation fedex overnight delivery buying Famvir without a prescription buy Famvir pay pal without prescription Famvir without dr purchase Famvir without a prescription overnight shipping how to buy Finpecia on line Abilify buy online purchase Abilify over the counter cod overnight Buy Famvir online pharmacy how to get a Famvir rx Abilify order online Non perscription cheap Finpecia buy discount Lisinopril on line buy Lisinopril no prescription low cost order Lisinopril pay pal online without rx buy Lisinopril online no perscription where to purchase cheap Lisinopril no rx buy Lisinopril now Maxalt purchase purchase Maxalt cod next day delivery where to buy Maxalt online purchase Maxalt online without rx best buy Maxalt Maxalt online maxalt overnight no script mastercard accepted cheap maxalt no script order arimidex overnight delivery purchase arimidex without a prescription online buy cheapest Arimidex and Arimidex buy no perscription Arimidex discount Arimidex achat Arimidex buy cheap online pharmacy Lisinopril How to get perscription of Lisinopril buy Lisinopril now Lisinopril order buy Amitriptyline no prescription Fluoxetine no prior script online Fluoxetine purchase cheap order rx Fluoxetine order Fluoxetine no visa without rx buy Fluoxetine toronto buy Fluoxetine drugs where can i buy herbal Fluoxetine prescription Fluoxetine buy Fluoxetine without doctor buy Fluoxetine on line Anafranil online purchase Anafranil from india Anafranil with repronex buy Anafranil amex online without prescription where to buy Anafranil online where can i purchase Anafranil without a prescription buy Anafranil pay pal without prescription Nizoral purchased online without prescription buy Aricept offshore no prescription fedex Aricept without prescription medications overnight Aricept without a rx uk Aricept generic how to order Amitriptyline online without a rx Accutane 40 mg delivered overnight Accutane 40 mg overnight delivery fed ex Accutane 40 mg overnight delivery fed ex where to purchase generic Accutane 40 mg online without a rx buy 40 mg Accutane free fedex delivery 40 mg Accutane uk order Amitriptyline Amitriptyline best buy generic Accutane 40 mg uk buy Accutane 40 mg in mo buy Accutane 40 mg uk buy generic Accutane 40 mg pills order 40 mg Accutane online next day delivery 40 mg Accutane ordering without a dr