Global blocks - or how to get the same content on every page

Ruud

[url=https://dev4me.com/modules-snippets/]Dev4me - WebsiteBaker modules[/url] - [url=https://wbhelp.org/]WBhelp.org[/url]

edwardca

Quote from: masju on January 31, 2009, 04:58:16 PM
Hi!

If your server does not allow the include-command in your template's index.php
<?php include (WB_URL."/pages/blocks/block1.php"); ?>
due to security-settings, try this instead:

<?php
$handle = fopen (WB_URL."/pages/blocks/block1.php", "r");
while (!feof($handle))
   {
    $buffer = fgets($handle, 4096);
    print_r ($buffer);
   }
?>

Works well :-)

greets masju

Yes!  Solved my problem - you rock dude!!

tkche

Hi,
I am trying to make a global block for a contact-form on my template.
the above code works great and gets the job done, but for some reason it includes the CSS style into the page's code.
any ideas?

lavric

Quote from: mr-fan on March 05, 2009, 09:23:48 AM
               <!-- global block starts here -->
               <div id="topleft"> <!-- change to your favorite css #id -->
               <?php
                ob_start
();
                
page_content(2); //INFOBOX PAGE CONTENT 2 in my case
                
$topl=ob_get_contents();
                
ob_end_clean();
                if (
$topl=="") {
                
$section_id 65// ID from the section that stays always if pagecontent 2 has no content
                
$query_sec $database->query("SELECT section_id,module FROM ".TABLE_PREFIX."sections WHERE section_id = '$section_id' ");
                if(
$query_sec->numRows() > 0) {
                
$section $query_sec->fetchRow();
                
$section_id $section['section_id'];
                
$module $section['module'];
                require(
WB_PATH.'/modules/'.$module.'/view.php');
                }
                } else {
                echo 
'<div align="center">';
                echo 
$topl;
                echo 
'</div>';
                }
                
?>

               </div>
               <!-- end of the global block -->



Hi guys,

i use this piece of code for global blocks!

I've got it from vyni!

The Trick is that you can have default view for a global block (with the section_id you choose) and if you want another content on one or more sites only set up a section and set it up to the content of the global block - and on this page the content is like you want it!

regards martin


This is WOW USEFUL!!! THANKS MAN!!!
I thought it wasn't too much trouble, but it was too much to ask...

mr-fan


Housy

Quote from: mr-fan on May 31, 2010, 10:18:58 AM
Quote from: Housy on May 31, 2010, 01:03:49 AM
What else can i try?

Tnx, Housy

hi Housy,

try this one in code section or in your template... :wink:

<?php
// here your section 
$section_id 65;

// query for section call
$query_sections $database->query("SELECT section_id,module FROM ".TABLE_PREFIX."sections WHERE section_id = '$section_id' ");

// query to check if section exists and output with fitting mod view.php
if($query_sections->numRows() > 0) {
$section $query_sections->fetchRow();
$section_id $section['section_id'];
$module $section['module'];
require(WB_PATH.'/modules/'.$module.'/view.php');

?>


best regards
martin

Martin I love you man :-D

Thank you very much, finally working :wink:

Thank you both, Martin and Klaus.

Housy

mr-fan

Quote from: Housy on May 31, 2010, 01:03:49 AM
What else can i try?

Tnx, Housy

hi Housy,

try this one in code section or in your template... :wink:

<?php
// here your section 
$section_id 65;

// query for section call
$query_sections $database->query("SELECT section_id,module FROM ".TABLE_PREFIX."sections WHERE section_id = '$section_id' ");

// query to check if section exists and output with fitting mod view.php
if($query_sections->numRows() > 0) {
$section $query_sections->fetchRow();
$section_id $section['section_id'];
$module $section['module'];
require(WB_PATH.'/modules/'.$module.'/view.php');

?>


best regards
martin

kweitzel

Things you can still do: Create a formpage for the submission action (make it hidden or something) and then:

1) Hardcode it into your template, like with the searchbox or the loginbox
2) Create a droplet (there are searchbox and loginbox available as sample)

but as action you take the submission of the formpage

cheers

Klaus

Housy

Quote from: kweitzel on May 30, 2010, 02:09:03 PM
Depending on the installed WB Version the Module is already included, have a look at the admin tools. A bit more info can be found here: http://www.websitebakers.com/pages/droplets/about-droplets.php

You copy the droplet code and past it into a "new" droplet which you can create in the admin of your WebsiteBaker installation. Name the droplet exactly like found on the site "ShowSection" and call it with [[showsection?section=xx]] (replace xx with the ID of your Section).

The Call can be placed in your template or in a section.

cheers

Klaus

Tnx Klaus but unfortunately that works only for the WYSIWIG editor and not for the built-in form module :|, cause i read that here in this theme --> CLICK and i also tryed to include form section but i get the error --> "Error in: showsection?section=33, no correct returnvalue.".

I just want to have a form on every single page, is that really so hard to do? This problem is killing me, i tryed everything but no result, nothing works as it should :-(

What else can i try?

Tnx, Housy

kweitzel

Depending on the installed WB Version the Module is already included, have a look at the admin tools. A bit more info can be found here: http://www.websitebakers.com/pages/droplets/about-droplets.php

You copy the droplet code and past it into a "new" droplet which you can create in the admin of your WebsiteBaker installation. Name the droplet exactly like found on the site "ShowSection" and call it with [[showsection?section=xx]] (replace xx with the ID of your Section).

The Call can be placed in your template or in a section.

cheers

Klaus

Housy

Quote from: kweitzel on May 29, 2010, 09:25:26 PM
Have you tried the droplet sectionpicker instead?

I have found something, but i'm not quite sure if that is what you had in mind --> CLICK
I don't understand actually, how that works to be honest :? What should i download, the droplet module and then what? :|

Could you please explain this more easily Klaus?

Thank you, Housy

kweitzel

Have you tried the droplet sectionpicker instead?

cheers

Klaus

Housy

Quote from: kweitzel on February 21, 2007, 06:56:46 PM
if it does not work, try curl instead:


$ch = curl_init();
$timeout = 5; // set to zero for no timeout
curl_setopt ($ch, CURLOPT_URL, WB_URL.'/pages/pagename.php');
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents = curl_exec($ch);
curl_close($ch);
// display file
echo $file_contents;


Thank you Klaus, that works, if i use WYSIWIG editor but if i want to create a form within admin area (if i use the built-in form module) then it doesn't work and i don't know where is the problem. For example if i create a name and e-mail field and i include that page within my template file, then it's printed out, it means that i see the form on my website but when i press the send/submit button, i'm redirected to a blank page, nothing happens actually and the link looks like this --> http://localhost/wb/pages/blocks/form.php#wb_33

If i access the link directly, like this --> http://localhost/wb/pages/blocks/form.php, then everything works fine, so the problem must be somewhere else, maybe i should set some setting or what, if you could help me please, cause i would really like to have a form on every single page but unfortunately that doesn't work as it should or maybe i'm stupid heh =D

Thank you, Housy

kweitzel

This is how I usually do my includes, since I don't like having the empty DIV within the template, maybe even styled and then no content in it.

But then again, I use them global blocks a bit differently, since they can also contain nothing!

Basically: If local block is empty try global block, if that one is empty show nothing" ...

cheers

Klaus

mr-fan

dear klaus,

yes you are right - but have you tested it?

i only want that this code work on other testenvironments, too....

this would be my final example for the tuttorial..... :wink:

tutorial would be about include, cURL, get by section, get by page_content (like the mentioned code) and put this together with the ouput buffer....to get it dynamically with a second/third block in the template....

regards martin

kweitzel

Hmm ... I personally would wrap the DIV in the output as well since it then hides headers if they are ot needed. A bit like this:



               <!-- global block starts here -->
               <?php
                ob_start
();
                
page_content(2); //PAGE CONTENT who should be replaced with global block
                
$topl=ob_get_contents();
                
ob_end_clean();
                if (
$topl=="") {
                    global 
$wb;
                    
$wb->page_id 14;  // page_id of the global block ?>

                   <div id="topleft"> <!-- change to your favorite css #id -->
                   <?php page_content(1);    // set up the block to show ?>
                   </div>
                   <?php
                
} else {
                    echo 
$topl;
                }
                
?>

               <!-- end of the global block -->



cheers

Klaus

mr-fan

hi,

i'am writing a tutorial for "global blocks" and with this work i worked a lot with all the mentioned options and possibilitys....

i've just combined my version (vyni's) and louSou's version to this one - it seems to work realy good!

But i've asking for some people who test this a little bit more!!

               <!-- global block starts here -->
               <div id="topleft"> <!-- change to your favorite css #id -->
               <?php
                ob_start
();
                
page_content(2); //PAGE CONTENT who should be replaced with global block
                
$topl=ob_get_contents();
                
ob_end_clean();
                if (
$topl=="") {
                                 global 
$wb;
                                 
$wb->page_id 14;  // page_id of the global block
                                 
page_content(1);    // set up the block to show
                                
} else {
                echo 
$topl;
                }
                
?>

               </div>
               <!-- end of the global block -->


it seems that this will we the most flexible way to setup a global block in a template! and you can choose to get different content on some pages, too!

have fun!

martin

crnogorac081

Aldo I didnt understood this part,
Quote
BUT if you setup on one of your pages a different page_content(2); (manage sections) the default view (section) change ONLY on this site to the block 2 content you like!

I now understand that this, your code, contains both <?php  page_content(2); ?> line,  and the coded from first post :))

So basicly you can choose to put your code or these 2 pieces of php :)

cheers

Web developer

mr-fan

hi ivan,

it it very simpel to explain!

if you have for eg. page_content(2); in your template for the second block!

replace it with this code and change the section ID to your needs!

so you've get a standart section that is shown in the second block (the section you set up)

BUT if you setup on one of your pages a different page_content(2); (manage sections) the default view (section) change ONLY on this site to the block 2 content you like!

example page from me: (only german - not valide - not my best one... :wink:)

http://www.mr-vilsbiburg.de/pages/maschinenring--e.v.-/vorstand.php

under "INFOBOX" the standardsection is a codesection with the "oneliner" droplet

like on this site, too:

http://www.mr-vilsbiburg.de/pages/dienstleistungen-gmbh/winterdienst.php

but on many many other sites there is a block 2 setup in the page settings itself and then the viewport is on the specialcontent for this page!

<?php //pseudocode
if block 2 has content - echo block 2 ....else echo section that is set in the codesnippet...


i hope its clear now - english is not my language - like you, too  :-D

regards martin


crnogorac081

Quote from: mr-fan on March 05, 2009, 09:23:48 AM
               <!-- global block starts here -->
               <div id="topleft"> <!-- change to your favorite css #id -->
               <?php
                ob_start
();
                
page_content(2); //INFOBOX PAGE CONTENT 2 in my case
                
$topl=ob_get_contents();
                
ob_end_clean();
                if (
$topl=="") {
                
$section_id 65// ID from the section that stays always if pagecontent 2 has no content
                
$query_sec $database->query("SELECT section_id,module FROM ".TABLE_PREFIX."sections WHERE section_id = '$section_id' ");
                if(
$query_sec->numRows() > 0) {
                
$section $query_sec->fetchRow();
                
$section_id $section['section_id'];
                
$module $section['module'];
                require(
WB_PATH.'/modules/'.$module.'/view.php');
                }
                } else {
                echo 
'<div align="center">';
                echo 
$topl;
                echo 
'</div>';
                }
                
?>

               </div>
               <!-- end of the global block -->




Hi Martin,

Could you explain me pls what is the point of this code ?

page_content(2); //INFOBOX PAGE CONTENT 2 in my case

As if you have for example left content box (1) and right sidebar (2) , If you want your block on right side, you will put this piece of code right before <?php  page_content(2); ?> , right ??

So I dont understand the point, or I am missing something... ??

cheers
Web developer

Hans

Hi lousou76
Thanks for your answer. Tried it again on an other install and it worked fine. Don't know why it failed the first time, I will try again and post if necessary.
Thanks again
Hans
Hans - Nijmegen - The Netherlands

lousou76

Hi Hans,
I don'nt think that is code related.

What the code below does is it changes the current page_id to the page that has the section you wish to display and then it prints the section number you want.

If the gallery works on the original page it should work on the other page as well.
At least it works on my tests.
I don;t know what else could be wrong.
I 've tested it with my gallery, a form etc and I had no error.

Regards,
LS


Quote from: Hans on May 16, 2009, 02:43:46 PM
Hi lousou76
I tried your code and it works great but not with an image gallery. Is there a way to make that work too?
Thanks
Hans

Hans

Hi lousou76
I tried your code and it works great but not with an image gallery. Is there a way to make that work too?
Thanks
Hans
Hans - Nijmegen - The Netherlands

lousou76

I use the below code all the time and it works great.
You can have the source page hidden or not.
All you have to do is put a code section instead of a block
and know the page_id and the section number you wish to display.

in the below example I display section 2 of page 14 on current section of page 16
You can display more than one on the same page and copy entire pages this way keeping the same template.
libcurl is buggy and will show empty block or timeout if something is wrong.
The below way replicates directly trhough the db using wb own methods.

Regards,
LS


global $wb;
$wb->page_id = 14;
page_content(2);
$wb->page_id = 16;  //I am not sure this is really necessary but just in case.



weiry

@mrfan and @klaus
Sorry, was trying to make things a little too cute and should have used the curl instead.

What I wanted, was one hidden page that may contain many hidden sections on it for a variety of different divs across many pages. I wanted to call in specific sections for certain pages determined by the template being used. i.e. 3 pages will reference one section for 1 div area (right-hand column) and 4 pages will reference another section for 1 div area (main content). That way the client changes it once on one hidden page and it is picked up across the different pages.

P.S. Just a note, I remembered there was a Droplets module ShowSection, so I was able to call in the specific section and then call in the remainder of the text on the page in that div if it had any. You could either put this Droplet as a Code section on the particular pages, or call it in through the index.php file. So a couple of solutions to my problem.

Hope that helps someone else.

Cheers.