Welcome, Guest. Please login or register.
Did you miss your activation email?
February 13, 2012, 03:37:50 AM

Login with username, password and session length
Search:     Advanced search
Interested in joining the WebsiteBaker team?
For more Information read here or on our new website.
149700 Posts in 21103 Topics by 7538 Members
Latest Member: ionline
* Home Help Search Login Register
Pages: [1]   Go Down
Print
Author Topic: Give each block separate classes  (Read 2312 times)
pushloop

Offline Offline

Posts: 1


« on: September 05, 2007, 06: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é
Logged
marathoner

Offline Offline

Posts: 495


« Reply #1 on: September 05, 2007, 08: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:
<?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";
}
?>

Logged
DGEC

Offline Offline

Posts: 386


WWW
« Reply #2 on: September 08, 2007, 02:16:28 AM »

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

Offline Offline

Posts: 184


« Reply #3 on: March 25, 2008, 08:18:41 AM »

Great..saved my project  grin. Thank you very much!
Logged
spida

Offline Offline

Posts: 203


« Reply #4 on: April 07, 2008, 12:55:39 PM »

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

Offline Offline

Posts: 495


« Reply #5 on: April 07, 2008, 02: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?
Logged
spida

Offline Offline

Posts: 203


« Reply #6 on: April 07, 2008, 08:33:49 PM »

Hi Marathoner,

your explanation makes perfectly sense. Thank you!

Regards,
spida
Logged
Pages: [1]   Go Up
Print
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!