Hi all,

I need to get the secondary links, using <?php print theme('links', $secondary_links); ?> in the template, in the left sidebar, so I have the following in my template -

<?php if ($left || $secondary_links: ?>
    <div id="sidebar-left">
        <?php print theme('links', $secondary_links); ?>
        <?php print $left; ?>
    </div>
 <?php endif; ?>

But I now need <?php print $body_classes; ?> to acknowledge the left sidebar when $secondary_links exist, but there are no blocks in $left.

I realise it gets these values from the layout variable:


  // Set up layout variable.
  $variables['layout'] = 'none';
  if (!empty($variables['left'])) {
    $variables['layout'] = 'left';
  }
  if (!empty($variables['right'])) {
    $variables['layout'] = ($variables['layout'] == 'left') ? 'both' : 'right';
  }

So how do I get this variable to acknowledge the presence of secondary links?
I'm sure this is easy as, according to the api, the layout variable is available to page.tpl.php, but my (very) limited php skills can't figure out how. (I'm using the excellent ZEN theme as a base, if there's an easy route there?)

Any help would be massively appreciated

Comments

mndonx’s picture

Could you just make your secondary links a block in the $left region through the blocks user interface (/admin/build/block/list)? That way $left will have content -- and you won't need to worry about hardcoding the secondary_links variable in the template at all.

pixelenvy’s picture

The secondary links are sourced from the primary links, so unfortunately the Secondary Links block doesn't work. It only works properly if you use "print theme('links')"

pixelenvy’s picture

Ok, I've got it... if anyone's interested:

function THEME_preprocess_page(&$vars, $hook) {
	// Set appropriate body classes if secondary nav exists
	// Set up layout variable.
	$vars['layout'] = 'none';
	if (!empty($vars['left']) || !empty($vars['secondary_links'])) {
		$vars['layout'] = 'left';
	}
	if (!empty($vars['right'])) {
		$vars['layout'] = ($vars['layout'] == 'left') ? 'both' : 'right';
	}
	
	// Set up new array to hold body classes
	$renew_body_classes = explode(' ', $vars['body_classes']);
	// Remove old sidebar classes
	$renew_body_classes = array_diff($renew_body_classes, array('no-sidebars', 'one-sidebar', 'two-sidebars', 'sidebar-right', 'sidebar-left'));
	// Add new information about the number of sidebars.
	if ($vars['layout'] == 'both') {
		$renew_body_classes[] = 'two-sidebars';
	}
	elseif ($vars['layout'] == 'none') {
		$renew_body_classes[] = 'no-sidebars';
	}
	else {
		$renew_body_classes[] = 'one-sidebar sidebar-'. $vars['layout'];
	}
	$vars['body_classes_array'] = $renew_body_classes;
	$vars['body_classes'] = implode(' ', $renew_body_classes); // Concatenate with spaces.
}
mndonx’s picture

Yay - glad you were able to figure out the override. Sorry I wasn't more help!

gtothab’s picture

This helped me a lot!

Thanks for posting it.