0

I've made a sub-theme of the Bootstrap theme; however, I am having trouble understanding where $variables comes from in the page.vars.php file. I made a little "debug" code to print out the variables - unfortunately, the output is exceptionally large and has some strange outputs. I have edited page.vars.php using the variables already retrieved from the $variables associative array, e.g. I edited the size of the main content section on the page:

 $variables['content_column_class'] = ' class="col-md-8 col-sm-6"';

This suggests there should be a 'content-column-class' in the $variables array; however, amazingly when I perform print_r($variables) it turns out there is none! Furthermore, every variable I have checked that is being accessed in page.vars.php seemingly does not exist.

I'd like to edit the class of the primary / sidebar_first sections; however, currently I cannot do this as I don't know how to access them from the $variables array.

In sum, why does print_r not output the expected? And, how do I find out what variables are actually in $variables?

  • did you rebuild theme registery? – Shabir A. Oct 29 '15 at 16:34
  • I'm guessing no (not a clue what you mean). I'll look into it! – monster Oct 29 '15 at 16:38
  • clear cache it will rebuild your theme registory – Shabir A. Oct 29 '15 at 16:48
0

The proper way to add a new variables in a class is to use hook_preprocess_page(&$vars) you can add the classes like the following:

$classes = array(
    'classes_main_page' => '',
    'classes_sidebar_first' => '',
    'classes_sidebar_second' => '',
  );

  // Classes when no sidebar
  if(empty($vars['page']['sidebar_first']) && empty($vars['page']['sidebar_second'])) {
    $classes['classes_main_page'] = 'small-12 medium-12 large-12';
  }
// Classes when left and right sidebars
  if(!empty($vars['page']['sidebar_first']) && !empty($vars['page']['sidebar_second'])) {
    $classes['classes_main_page'] = 'small-12 medium-6 large-6 columns';
    $classes['classes_sidebar_first'] = 'small-12 medium-3 large-3 columns';
    $classes['classes_sidebar_second'] = 'small-12 medium-3 large-3 columns';
  }

  // Classes when only left sidebar
  if(!empty($vars['page']['sidebar_first']) && empty($vars['page']['sidebar_second'])) {
    $classes['classes_main_page'] = 'small-12 medium-9 large-9 columns';
    $classes['classes_sidebar_first'] = 'small-12 medium-3 large-3 columns';
  }

  // Classes when only right sidebar
  if(empty($vars['page']['sidebar_first']) && !empty($vars['page']['sidebar_second'])) {
    $classes['classes_main_page'] = 'small-12 medium-9 large-9 columns';
    $classes['classes_sidebar_second'] = 'small-12 medium-3 large-3 columns';
  }
$vars = array_merge($vars, $classes);

and then in your page.tpl.php print something like this:

Don't forget to clear cache afterwards

<aside class="<?php print $classes_sidebar_second; ?>"> for sidebars
<aside class="<?php print $classes_sidebar_second; ?>"> for main container

Thanks

  • Ok. But how do you know what the items in the array are? Without knowing the names I can't correctly add classes to the elements. – monster Oct 29 '15 at 16:39
  • use in your tpl file <aside class="<?php print $classes_sidebar_second; ?>"> – Shabir A. Oct 29 '15 at 16:50
  • added explanation to the answer. hope it will help now – Shabir A. Oct 29 '15 at 16:52

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.