WebsiteBaker Community Forum

WebsiteBaker Support (2.8.x) => Droplets & Snippets => Topic started by: pushloop on September 05, 2007, 07:52:19 PM

Title: Give each block separate classes
Post by: pushloop on September 05, 2007, 07:52:19 PM
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é
Title: Re: Give each block separate classes
Post by: marathoner on September 05, 2007, 09:14:57 PM
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:

Code: [Select]
<?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";
}
?>

Title: Re: Give each block separate classes
Post by: DGEC on September 08, 2007, 03:16:28 AM
Beautiful solution, Marathoner.
I'm raw with PHP, didn't know you could do something like that. Cool!
Title: Re: Give each block separate classes
Post by: Lotus on March 25, 2008, 08:18:41 AM
Great..saved my project  :-D. Thank you very much!
Title: Re: Give each block separate classes
Post by: spida on April 07, 2008, 01:55:39 PM
Hey,

great solution!
I might misunderstand your code, marathoner, but I think there is a tiny error in it.
In
Code: [Select]
<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
Code: [Select]
<div id="content">
<?php if ($content1<>"") { // Next test $content1 to see if there is something in it
   
echo "<div id=\"content1\">\n";
}
?>
?
Title: Re: Give each block separate classes
Post by: marathoner on April 07, 2008, 03:43:40 PM
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?
Title: Re: Give each block separate classes
Post by: spida on April 07, 2008, 09:33:49 PM
Hi Marathoner,

your explanation makes perfectly sense. Thank you!

Regards,
spida