Hi y'all
I'm trying to set up page_content(2) and page_content(3) to show up with a frame around each using CSS.
I could place each content inside a div, and then give both divs the same class. But the problem then is that I would have to fill both page_contents with text, otherwise the borders will show up anyway, leaving just an empty box.
Basically, I would like the boxes with borders to show up only if there is any content!
Is there any way to automatically give each content a "<div class="something"> text </div>" by modifying the php-code?
Any help or ideas asap would be highly appreciated!
Tnx
/André
Just modify your template to check to see if a certain section exists before you include that section. I have modified my template to display various columns (actually blocks) if a page has two blocks otherwise use the entire width to display the contents if there is only one block. Here's a snippet from my template:
<?php ob_start(); // Start the outputbuffer
page_content(2); // Next call the block
$content2=ob_get_contents(); // Now fetch the output into a variable
ob_end_clean(); // Clean up old mess and stop buffering
?>
<div id="content">
<?php if ($content2<>"") { // Next test $content2 to see if there is something in it
echo "<div id=\"content1\">\n";
}?>
<?php page_content(1);
echo "\n</div><!-- close div#content1 -->\n";
?>
<?php if ($content2<>"") { // Next test $content2 to see if there is something in it
echo "<div id=\"content2\">\n";
echo $content2;
echo "\n</div><!-- close div#content2 -->\n";
}?>
<?php if ($content2<>"") { // Close the div tag for $content2 if it was used
echo "</div><!-- close div#content -->\n";
}?>
Beautiful solution, Marathoner.
I'm raw with PHP, didn't know you could do something like that. Cool!
Great..saved my project :-D. Thank you very much!
Hey,
great solution!
I might misunderstand your code, marathoner, but I think there is a tiny error in it.
In <div id="content">
<?php if ($content2<>"") { // Next test $content2 to see if there is something in it
echo "<div id=\"content1\">\n";
}?>
shouldn't it be instead
<div id="content">
<?php if ($content1<>"") { // Next test $content1 to see if there is something in it
echo "<div id=\"content1\">\n";
}?>
?
No, that is not an error. Here's my logic...I already know that every page will have something in content1 but only some pages will have both content1 and content2.
I only want to use a right and left column (div1 and div2) if there are two content blocks...so I need to test to see if there is anything in content2. If there is no content2 then content1 doesn't need wrapped by div1 (which I use for a right column. This means that content1 only pages will occupy the full width and that pages with content2 will use a right and left column. Make sense?
Hi Marathoner,
your explanation makes perfectly sense. Thank you!
Regards,
spida