0

How do I add a class to a panel page's body element without having to add it manually in the variant configuration section? I want all panel pages to have a body element with the class 'panel-page'. Is there some kind of hook like hook_panel_page()?

2

You can use menu_get_item() to inspect what generated the page and add a class to the body element in template_preprocess_html(). I saw the code first in the Zen theme, where they also add a class if the page was generated by Views. Link to Zen template.php

    function MYTHEME_preprocess_html(&$variables, $hook) {
      // Store the menu item.
      $variables['menu_item'] = menu_get_item();
      if ($variables['menu_item']) {
        switch ($variables['menu_item']['page_callback']) {
          case 'page_manager_blog':
          case 'page_manager_blog_user':
          case 'page_manager_contact_site':
          case 'page_manager_contact_user':
          case 'page_manager_node_add':
          case 'page_manager_node_edit':
          case 'page_manager_node_view_page':
          case 'page_manager_page_execute':
          case 'page_manager_poll':
          case 'page_manager_search_page':
          case 'page_manager_term_view_page':
          case 'page_manager_user_edit_page':
          case 'page_manager_user_view_page':
            // Is this a Panels page?
            $variables['classes_array'][] = 'page-panels';
            break;
        }
      }
    }
0

To override the default template, copy panels-pane.tpl.php from panels > templates to your theme, and clear the cache. Then, manually add the CSS classes you need in your template file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.