Welcome, Guest. Please login or register.
Did you miss your activation email?
May 27, 2012, 06:17:35 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.
155555 Posts in 21715 Topics by 7737 Members
Latest Member: gx-world
* Home Help Search Login Register
Pages: [1]   Go Down
Print
Author Topic: If page_content(2) exists then...  (Read 936 times)
evildmp

Offline Offline

Posts: 64


« on: January 21, 2008, 10:34:21 PM »

I want to add a class to a <div> if and only if page_content(2) is not empty for that page.  So I need something like:

Code:
if [page_content(2) is non-empty] { echo ' narrow'; }

What would the actual code be?

Thanks,

Daniele
Logged
powderbomber

Offline Offline

Posts: 55


« Reply #1 on: January 22, 2008, 04:04:15 AM »

not exactly sure if this will help, but it sounds like something the output buffer would be able to do... search the forum for that or ob - or look for it in some of the templates. Ive made some pretty complicated ones that check to see if sections exist
Logged
Netzperlentaucher

Offline Offline

Posts: 21


WWW
« Reply #2 on: January 22, 2008, 09:00:48 AM »

Chio has published some very useful hints and tricks on his German website. Look at this: http://www.beesign.com/websitebaker/pages/posts/spielereien-mit-bloecken19.php

Trick 2 might be the key...
« Last Edit: January 22, 2008, 09:03:23 AM by Netzperlentaucher » Logged

WB-Templates
Memofritz - Denk dran!
marathoner

Offline Offline

Posts: 495


« Reply #3 on: January 22, 2008, 07:10:13 PM »

I use the code below in my template to see if there is anything in page_content(2). I use this in conjunction with two CSS classes for a right and left column. If there is page_content(2) then use class "content1" for my left column (stored in page_content(1)) and class "content2" for my right column (stored in page_content(2)). If there is page_content(2) is empty then I use the entire width for page_content(1).

Hope this helps.

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
evildmp

Offline Offline

Posts: 64


« Reply #4 on: January 27, 2008, 10:55:14 AM »

I use the code below in my template to see if there is anything in page_content(2). I use this in conjunction with two CSS classes for a right and left column. If there is page_content(2) then use class "content1" for my left column (stored in page_content(1)) and class "content2" for my right column (stored in page_content(2)). If there is page_content(2) is empty then I use the entire width for page_content(1).

That's exactly what I was trying to do myself - in the end I managed to get the output buffer function to work, it does the job nicely.
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!