Welcome, Guest. Please login or register.
Did you miss your activation email?
May 23, 2012, 07:12:14 PM

Login with username, password and session length
Search:     Advanced search
Wollen Sie dem WebsiteBaker Team beitreten?
Nähere Informationen finden Sie unter hier und auf unserer neuen Webseite.
155439 Posts in 21702 Topics by 7732 Members
Latest Member: Smacki
* Home Help Search Login Register
Pages: [1]   Go Down
Print
Author Topic: (Global) section to show if content inside PHP-help  (Read 1717 times)
Lotus

Offline Offline

Posts: 184


« on: August 20, 2008, 08:05:03 AM »

Hello, wonder if someone could take a look att this PHP-code. Following code is made by http://www.beesign.com and its used in the template to show a content block only if there are any content in it.

I would very much have the same features but insted output a specific section. That is, it takes a look at the section and write it out if there are content in the section.

Code:
   
<?php ob_start(); 
    
page_content(1); 
    
$content1=ob_get_contents();  
    
ob_end_clean(); 
?>
   
<?php if ($content1<>"") { 
        echo 
"<div id=\"name\">\n";
        echo 
$content1;
        echo 
"\n</div><!-- close div#name -->\n";
}
?>


I am sure it is trivial to any PHP-coder. The content needs to be stored in an variable but i can not figure out how? Manage to do it with a menu though so I am sharing this below.

Menu shows only if there are content:

Code:
   
<?php ob_start(); 
    
show_menu2(1,SM2_ROOT+1); 
    
$content1=ob_get_contents();  
    
ob_end_clean(); 
?>
   
<?php if ($content1<>"") { 
        echo 
"<div id=\"left1\">\n";
    echo 
"<div id=\"meny\">\n";
        echo 
$content1;
    echo 
"\n</div><!-- close meny-->\n";
        echo 
"\n</div><!-- close left1-->\n";
}
?>

Logged
kweitzel
Forum administrator
*****
Offline Offline

Posts: 6975


WWW
« Reply #1 on: August 20, 2008, 01:04:35 PM »

The way you put it, the output of the show menu2 function is stored in the variable ... if you want to use section blocks, just change the page_content(1) to whatever other section block of the defined ones you want to use.

If it is about sections assigned to the main block, you need to manually pull the from the DB.

cheers

Klaus
Logged

WebsiteBaker Org e.V. - for WebsiteBaker

Lotus

Offline Offline

Posts: 184


« Reply #2 on: August 20, 2008, 03:12:52 PM »


If it is about sections assigned to the main block, you need to manually pull the from the DB.

cheers

Klaus

Yeah, how do I du that? =), lets say i want the section with ID=666
Logged
Stefek
WebsiteBaker Org e.V.

Offline Offline

Posts: 4884



« Reply #3 on: August 20, 2008, 04:03:05 PM »

Hello Lotus,

you may have a look on the "Andreas06 - Falling Leaves" Templates.
http://addons.websitebaker.org/pages/templates.php

It's using the wanted behaviour and is very well documented.
You will find your Solution inside this template.

Best Regards,
Stefek
Logged

"In a time of universal deceit, telling the truth becomes a revolutionary act."
- George Orwell, Nineteen eighty-four (1984)
Lotus

Offline Offline

Posts: 184


« Reply #4 on: August 21, 2008, 09:45:22 AM »

Hello Lotus,

you may have a look on the "Andreas06 - Falling Leaves" Templates.
http://addons.websitebaker.org/pages/templates.php

It's using the wanted behaviour and is very well documented.
You will find your Solution inside this template.

Best Regards,
Stefek


Had a look at it and it seems like his PHP-code also looking if content in a block, i want to check if there are content in a section but maybe you are telling med someting i just dont understand  grin

Andreas code
Code:
<?php ob_start();     // start output buffer
page_content(2);   // call content
$foo=ob_get_contents();    // put outputbuffer in $foo
ob_end_clean();             // clear outputbuffer
if ($foo<>"") {  // some code to execute cause there is some block
..

it shall be something like this in the template
<?PHP
 Check if section ID 666 has content
 If section has content
 write out the content of theese lines of code
 else
 write out theese lines of code aka. nothing
?>
Logged
Stefek
WebsiteBaker Org e.V.

Offline Offline

Posts: 4884



« Reply #5 on: August 21, 2008, 10:00:59 AM »

All right, I got it.

I didn't understand you before.

Sorry.

This one I unfortunatly can't help you.

Regards,
Stefek
Logged

"In a time of universal deceit, telling the truth becomes a revolutionary act."
- George Orwell, Nineteen eighty-four (1984)
aldus

Offline Offline

Posts: 1238


« Reply #6 on: August 21, 2008, 10:12:16 AM »

Imho the main problem is, that differ sections belongs to differ modules;
and every modul holds his content in a different way; e.g. the guestbook in
another field-set as the anyNews modul. So you will have to handel many situations of
"got content" - "got no content".

Regards
Aldus
Logged
Ruud
WebsiteBaker Org e.V.

Offline Offline

Posts: 2294



WWW
« Reply #7 on: August 21, 2008, 01:08:22 PM »

You could try the section picker module.

It displays a section within a block.
If the section does not exist anymore, it will not do anything. (without errors)
If the section is saved empty it will display an empty section (a.k.a. nothing)

The section will be displayed using the linked module view.php. You can also use it for including forms/calendars/etc..

Ruud
Logged

Professional WebsiteBaker Solutions
Lotus

Offline Offline

Posts: 184


« Reply #8 on: August 21, 2008, 01:18:05 PM »

You could try the section picker module.

It displays a section within a block.
If the section does not exist anymore, it will not do anything. (without errors)
If the section is saved empty it will display an empty section (a.k.a. nothing)

The section will be displayed using the linked module view.php. You can also use it for including forms/calendars/etc..

Ruud


Maybe i could use some of the code in the module to modify my template but its too advanced for me..

..thanx anyway Ruud.

..and thank you Stefek

All right, I got it.

I didn't understand you before.

Sorry.

This one I unfortunatly can't help you.

Regards,
Stefek

..and Aldus ..just interested in a WYSIWYG section..

« Last Edit: August 21, 2008, 01:30:22 PM by Lotus » 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!