By joelfoit on
How would you please use the template.php file to check whether the right sidebar is present or not and then display a 3 column or 2 column layout accordingly?
We are technically not supposed to do any php logic inside our page.tpl.php so I could NOT do the following:
if($right !=""): //if right nav is present,
<div id="three_column">...</div>// then display a 3 column layout
else:
<div id="two_column">...</div> //display a 2 column instead.
//The above is wrong because it's highly recommended NOT to put php logic inside page.tpl.php but rather //use theme function overrides in our template.tpl.php where most of the php logic would typically go.
//So, how would I implement the same functionality for displaying a 2 or 3 column layout based on whether //there was a right nav or not OR based on anything, using the template.tpl.php and NOT what I did //above??????
A good solution would show only code in template.tpl.php :)
Thanks guys, I really need help out here. Thx again.
Comments
A number of themes use
A number of themes use approach similiar to the one found in the Fusion theme. In template.php they implement hook_preprocess_page() and add a 'body_classes' value that holds one or more classes that represent information about the page including the presence/absence of columns. The variable is then printed as the class value for the body tag and the classes used to conditional style the layout.
Can I print out the return value of a function
Can I do something like this?
I am just a drupal newbie but I learned some php and it's helped me picked up a great deal, plus the community, you guys, are incredibly helpful.
So, can I do this?
You could call the code below sudo code, I am just laying out the idea I have in mind, this might not be the right synthax.
And then back over to the page.tpl.php
">content here
?>
The idea here is this div would inherit or be passed either class_2 for a 2 column layout in my css or class_3 based on the php logic back in the template.php file.
Do you hopefully get a better idea of what I am trying to do here?
Help much appreciated !
Thx
The tpl file would use
The tpl file would use something like
and in template.php something like
print_r or dsm? but thx anyhow
Thank you so much,
I will try that and see what happens. So far, the function works in my template.php but the $colum_id variable is empty, it doesn't print anything so I get something like
where $colum_id is empty.
I am gonna see if I can print out the content of $vars that r passed in to see which specific variable is responsible for outputting the id field. something like this: