User login

Printing classes for a theme depending on sidebar

<?php
function _phptemplate_variables($hook, $vars = array()) {
  switch ($hook) {
    case 'page':
      // our own hook to remove sidebars from admin pages, not relevant here
      if (arg(0) == 'admin') {
        $vars['sidebar_right'] = '';
      }
     
      // layout for body classes
      $vars['layout'] = '';

      $layout = '';
      //Is there a left sidebar?
      if ($vars['sidebar_left'] != '') {
          $layout = 'sidebar-left';
      }
      //Is there a right sidebar?
      if ($vars['sidebar_right'] != '') {
           $layout = ($layout == 'sidebar-left') ? 'sidebars' : 'sidebar-right';
      }
      if ($layout != ''){
         $vars['layout'] .= ' ' . $layout;
      }
      break;     
  }
  return $vars;
}
?>

And if you want to see everything that's going on, this can be thrown in before the return statement, or at the top, to see what's there before you mess with it:

<?php
global $user; if ($user->uid == 1)  drupal_set_message('<pre>'. var_export($vars,TRUE) .'</pre>');
?>

(Internal Agaric note: Instead of a note to remove if we truly never use left sidebars, which we do not, we just link here on how to put this more complex code back.)

Resolution

Searched words: 
phptemplate variables show body class layout

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.