I need to check if the left and/or right regions are being displayed for the current page.

If I could load the $body_classes variable into my module I could simply search its value for either "left-sidebar", "right-sidebar" or "two-sidebars", but I can't find a way to do this.

Any ideas much appreciated.

Comments

nevets’s picture

Generally the presence/absence of the sidebars happens late in the pipeline, what function are you trying determine this in?

fiasst-1’s picture

I'm trying to access this from a custom module, block, .tpl file or just about anywhere.

I have a phptemplate_preprocess_page() function in template.php and I've considered setting a session with the available value in there but I'm sure that's not the best practice...

nevets’s picture

What sort of things are you trying to control based on the presence or absence of the sidebars. I am used to controlling css but that does that can already be done.

fiasst-1’s picture

Yeah, I'm using body_classes to manipulate CSS but that isn't enough for the problem im facing. I have nodes in a view which float left of each other in 5 columns if no sidebars are displayed, 4 columns if 1 sidebar is displayed and 3 columns of 2 sidebars are displayed. That's fine but the nodes have a right margin and the last node in each row needs no right margin in order to fit its parent container.

Example:

.node {
margin: 0 10px 10px 0;
}
.node.last {
margin-right: 0;
}

node.tpl

//$numcolumns = 3, 4 or 5 depending on how many sidebars are displaying
if ($page == 0){
global $product_tNUM;
$product_tNUM++;
print "<div class=\"node".(($product_tNUM % $numcolumns == 0)?' last' : '')."\">\n".
//....
"</div>\n";

So apparently, if the sidebars are set late on in the pipeline, I'll need to find a clever CSS only solution :\

FilipVandueren’s picture

If they have a fixed width and just float, or are inline-blocks, the divs should fill up all the space available, be it 3 4 or 5 columns worth.
of course you can still set different widths for the three scenarios by checking the body-class

Also, you can get the same spacing effect with using only margin-left, no ?

fiasst-1’s picture

Well, without going into a mass of detail, my problem went beyong CSS and I needed a 1 stop place to check how many nodes to display per row in a view.

I've created a function in a custom module to simply manage this information in one place:

function custom_sidebar_manager(){
	$columns = 5;
	if (!drupal_is_front_page()){
		if (arg(0) == 'taxonomy' && arg(1) == 'term'){
			$columns = 4;
		}
		elseif (arg(0) == 'node' && is_numeric(arg(1))){
			$columns = 3;
		}
	}
	return $columns;
}

Thanks for your time anyway and explaining that the sidebars are defined late in the process.