First I am very new to Drupal but loving it more every day... Coming from Joomla I am trying to get my head thinking in a different direction.

I am making a new theme for a Drupal (just toying and learning) but coming from the Joomla world it is quite easy to do width based on variables in the manner I am use to. In Joomla I would do somehting like:

<?php
if ( mosCountModules('left')) {
	$content_width = 880 - 180;
}
?>

down in the theme

<div id="body" style="width:<?php echo $content_width ?>px">

Then my content width would be 700. My problem arises when attempting use the same logic with Drupal. Since Drupal uses print() I altered my code to read

<?php
if ($sidebar_left) {
	$content_width = 880 - 180;
}
?>

Problem is, it not populating <?php echo $content_width ?>px"> and if I modify it to

<?php
if (print $sidebar_left) {
	$content_width = 880 - 180;
}
?>

I get what I want, but then I get data posted along the lefthand side of my screen because its reading the if exist statement. It doesn't seem to find the $sidebar_left variable alone but needs the whole (print $sidebar_left) statement.

Anyone have any ideas on how to get around the little problem? The only thing I can thing of, would be to write a wrapper, but I am hoping there is an easier way.

Comments

nevets’s picture

Try using isset() like this

if ( isset($sidebar_left) ) {
sm8417’s picture

I didn't even think about that... Thanks so much.

MasterSolution’s picture

The thing is that:

<?php
if (print $sidebar_left) {
    $content_width = 880 - 180;
}
?>

Will always return true, because "print $sidebar_left" will always be true.

Not sure if isset() would work because maybe the variable is set but doesn't necessarily have any content. I don't know how drupal treats this. I think the best approach would be to use the empty() function.

<?php
if  (!empty($sidebar_left)) {
    $content_width = 880 - 180;
}
?>

Martin
Web Solutions