WebsiteBaker Support (2.8.x) > Droplets & Snippets

Give each block separate classes

(1/2) > >>

pushloop:
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é

marathoner:
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: ---<?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";
}?>

--- End code ---

DGEC:
Beautiful solution, Marathoner.
I'm raw with PHP, didn't know you could do something like that. Cool!

Lotus:
Great..saved my project  :-D. Thank you very much!

spida:
Hey,

great solution!
I might misunderstand your code, marathoner, but I think there is a tiny error in it.
In
--- Code: ---<div id="content">
<?php if ($content2<>"") { // Next test $content2 to see if there is something in it
   echo "<div id=\"content1\">\n";
}?>
--- End code ---
shouldn't it be instead

--- Code: ---<div id="content">
<?php if ($content1<>"") { // Next test $content1 to see if there is something in it
   echo "<div id=\"content1\">\n";
}?>
--- End code ---
?

Navigation

[0] Message Index

[#] Next page

Go to full version