This is a bit specific question but i guess it could also be used for other menu's. So before panels_everywhere i used to print out my menu like so:

print theme('links__system_main_menu', array('links' => $main_menu, 'attributes' => array('id' => 'main-menu-ul', 'class' => array('nav'))));

I could add an additional class nav, but now, using panels_everywhere, i cant seem to find a way to add the class. Really need it to have my theme working.

Comments

merlinofchaos’s picture

You've got a couple of options!

1) Add the CSS class you need to the pane wrapper. Not ideal since in general I prefer to use the naked style on panes like this.
2) If using the 'Navigation' pane, use a preprocess to change the rendering to your liking.
3) Create a custom pane that renders exactly as you need, copying from the original pane as needed.

Michsk’s picture

1) Agreed. I also like the naked style and 9 out of 10 times i even rip out all that html from those templates. Second i need that class to be on the ul (twitter bootstrap).
2) Guess it will be this option.
3) This option does not give me the option to put the class on the ul right?

merlinofchaos’s picture

Creating the custom pane gives you the most flexibility and the leanest markup possible because it puts you in total control.

Michsk’s picture

Ok, I'll go for option 3.

Would you do it trough a custom pane with php or just programmatically? Don't know if there is any influence on caching or speed? Guess using php in a custom pane will have to go trough eval() every time so that will be slower right?

Second, i don't know if this is a bug but when i tried option two, it went 'wrong' when using the preprocess:

<?php
function indepressie_process_pane_navigation(&$vars) {
  $vars['main_menu'] = theme('links__system_main_menu', array(
    'links' => $vars['main_menu'],
    'attributes' => array('id' => 'main-menu', 'class' => array('nav')),
  ));
}
?>

The template i cleaned up to only $main_menu, but when using the above preprocess it does not return the links, the <ul> is shown but without the inner links.

Michsk’s picture

So im trying to get this done, here is my main_menu.inc

<?php
/**
* This plugin array is more or less self documenting
*/
$plugin = array(
  // the title in the admin
  'title' => t('Main menu'),
  'single' => TRUE,
  'category' => array(t('Everywhere'), -9),
  'render callback' => 'main_menu_pane_content_type_render'
);

function main_menu_pane_content_type_render($subtype, $conf, $args, $context = NULL) {
  $block = new stdClass();
  $block->content = theme('links__system_main_menu', array('links' => $main_menu, 'attributes' => array('id' => 'main-menu-ul', 'class' => array('nav'))));;
  return $block;
}
?>

So now.... :-P, do i have to go as deep as you have with the pane_navigation, as in creating a whole template for this, or can i stick just to code somehow.

//edit: for those creating ctools content types, here's a good tutorial with the basics http://www.nicklewis.org/drupal/tutorials/ctools-custom-content-types

Michsk’s picture

So this is what i would expect:

<?php
function main_menu_pane_content_type_render($subtype, &$context ) {
  $menu = menu_load('main_menu');
	$block = new stdClass();
  $block->content = theme('menu_link', array('links' => $menu, 'attributes' => array('id' => 'main-menu-ul', 'class' => array('nav'))));
  return $block;
}
?>

But that doesn't seem to be it.

Michsk’s picture

Here's what im doing now:

<?php
function main_menu_pane_content_type_render($subtype, &$context ) {
	$menu = drupal_render(menu_tree_output(menu_tree_all_data($pid)));
	$block = new stdClass();
  $block->content = $menu;
  return $block;
}
?>

This prints what i need. Now i only need the get the class in there.

Michsk’s picture

Here's the final working code:
main_menu.inc

<?php
/**
* This plugin array is more or less self documenting
*/
$plugin = array(
  // the title in the admin
  'title' => t('Main menu'),
  'single' => TRUE,
  'category' => array(t('Everywhere'), -9),
  'render callback' => 'main_menu_pane_content_type_render'
);

function main_menu_pane_content_type_render($subtype, &$context ) {
	$pid = variable_get('menu_main_links_source', 'main-menu');
	$menu = drupal_render(menu_tree($pid));
	$block = new stdClass();
  $block->content = $menu;
  return $block;
}
?>

template.php

<?php
function indepressie_menu_tree(&$variables) {
  return '<ul class="menu nav">' . $variables['tree'] . '</ul>';
}
?>
Kristen Pol’s picture

Title: Add clas to primary links menu » Add class to primary links menu
RowboTony’s picture

Brilliant! Thank you lasac! I'm building sites on the NodeStream distribution now and I was having trouble with this very thing, thanks for the plugin, works great!

Thanks also to Kristin for the title cleanup which allowed me to find this fix in the top search results, it's the little things that make big differences, that's why I love this community!

DamienMcKenna’s picture

Issue summary: View changes
Status: Active » Fixed

Thanks for the example code, Lasac!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.