Author Topic: Global blocks - or how to get the same content on every page  (Read 58717 times)

Offline kweitzel

  • WebsiteBaker Org e.V.
  • **
  • Posts: 6983
  • Gender: Male
Re: Global blocks - or how to get the same content on every page
« Reply #25 on: January 31, 2009, 09:06:28 PM »
That works as well if fopen is allowed on the host. Sometimes you find this one to be disabled as well.

Info: http://phpsec.org/projects/phpsecinfo/tests/allow_url_fopen.html

cheers

Klaus

Offline lousou76

  • Posts: 123
Re: Global blocks - or how to get the same content on every page
« Reply #26 on: March 04, 2009, 11:33:07 PM »
Excellent work Klaus!

It's a nice way of using global block sections that could be edited once instead of copying content form one page to another.

I guess the best way to do this would be a new nice page_content() function that could take 2 arguments instead of one. The page_id and the section_id.

That way you could just use for example <? page_content(1,3);  ?> to display content from another page on your site. You could also add this code on a Code section anywhere on your current page and show the same content with some other page.

I would advise against using curl to do this. If it hangs or it delays the page never loads or loads empty.

So lets see how to slightly change the page_content function, or add a new one that does what we want so we can have global blocks anywhere.

I ll have more on that later..

Regards,
LS
 

Offline lousou76

  • Posts: 123
Re: Global blocks - or how to get the same content on every page
« Reply #27 on: March 05, 2009, 12:05:59 AM »
Well it's really very simple.

If you want to display content from another page (regardless of what type of module it is) you only need to know the page_id ans the section_id of the content you need to show.

Lets say you are on /admin/pages/modify.php?page_id=16

and you want to show content from page_id=14 section_id=2.

You just add a code section on the current page and put the code
Code: [Select]
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.

This will display the exact type of module and content on the current section with page_id=14 and section_id=2.

Regards,
LS

mr-fan

  • Guest
Re: Global blocks - or how to get the same content on every page
« Reply #28 on: March 05, 2009, 09:23:48 AM »
Code: [Select]
               <!-- 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 = &#39;$section_id&#39; ");
                if(
$query_sec->numRows() > 0) {
                
$section $query_sec->fetchRow();
                
$section_id $section[&#39;section_id&#39;];
                
$module $section[&#39;module&#39;];
                
require(WB_PATH.&#39;/modules/&#39;.$module.&#39;/view.php&#39;);
                
}
                } else {
                echo &
#39;<div align="center">&#39;;
                
echo $topl;
                echo &
#39;</div>&#39;;
                
}
                
?>

                </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

Offline weiry

  • Posts: 92
Re: Global blocks - or how to get the same content on every page
« Reply #29 on: May 13, 2009, 08:11:38 AM »
I have found that this code works fine for calling in a block on every page that I have created on a hidden page.

However, if I have content already on another the page in that div area i.e. on the Contact Us page, the block I want on every page disappears and the text on the Contact Us page is there okay in that div area.

I am sure that it is a quick php thing, but can't see how to fix.

Any thoughts?

mr-fan

  • Guest
Re: Global blocks - or how to get the same content on every page
« Reply #30 on: May 13, 2009, 12:16:20 PM »
link? more details? code?.......my telephaty-power is burst up.... :-D

Offline kweitzel

  • WebsiteBaker Org e.V.
  • **
  • Posts: 6983
  • Gender: Male
Re: Global blocks - or how to get the same content on every page
« Reply #31 on: May 13, 2009, 09:33:38 PM »
@weiry: above code is working as designed, it is meant to do this! If no content assigned to this div call the hidden div.

You can just try to hard-code an include if you don't want this feature ... set the "hidden" page to template blank and then:
Code: [Select]
<?php include WB_URL.&#39;/pages/name_of_hidden_page.php&#39;; ?>
If include does not work (disabled), use the cURL (if installed on server) like described further above instead.

cheers

Klaus

Offline weiry

  • Posts: 92
Re: Global blocks - or how to get the same content on every page
« Reply #32 on: May 14, 2009, 02:42:09 AM »
@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.

Offline lousou76

  • Posts: 123
Re: Global blocks - or how to get the same content on every page
« Reply #33 on: May 15, 2009, 01:27:08 PM »
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

Code: [Select]
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.


Offline Hans

  • Posts: 914
  • Gender: Male
Re: Global blocks - or how to get the same content on every page
« Reply #34 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 - Nijmegen - The Netherlands

Offline lousou76

  • Posts: 123
Re: Global blocks - or how to get the same content on every page
« Reply #35 on: May 18, 2009, 02:18:31 PM »
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


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

Offline Hans

  • Posts: 914
  • Gender: Male
Re: Global blocks - or how to get the same content on every page
« Reply #36 on: May 18, 2009, 07:15:39 PM »
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

Online crnogorac081

  • Posts: 2085
  • Gender: Male
Re: Global blocks - or how to get the same content on every page
« Reply #37 on: August 18, 2009, 11:21:50 PM »
Code: [Select]
               <!-- 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 = &#39;$section_id&#39; ");
                if(
$query_sec->numRows() > 0) {
                
$section $query_sec->fetchRow();
                
$section_id $section[&#39;section_id&#39;];
                
$module $section[&#39;module&#39;];
                
require(WB_PATH.&#39;/modules/&#39;.$module.&#39;/view.php&#39;);
                
}
                } else {
                echo &
#39;<div align="center">&#39;;
                
echo $topl;
                echo &
#39;</div>&#39;;
                
}
                
?>

                </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

mr-fan

  • Guest
Re: Global blocks - or how to get the same content on every page
« Reply #38 on: August 19, 2009, 07:54:38 PM »
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!

Code: [Select]
<?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


Online crnogorac081

  • Posts: 2085
  • Gender: Male
Re: Global blocks - or how to get the same content on every page
« Reply #39 on: August 19, 2009, 08:25:04 PM »
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

  • Guest
Re: Global blocks - or how to get the same content on every page
« Reply #40 on: October 04, 2009, 08:42:43 PM »
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!!

Code: [Select]
               <!-- 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
« Last Edit: October 04, 2009, 08:44:33 PM by mr-fan »

Offline kweitzel

  • WebsiteBaker Org e.V.
  • **
  • Posts: 6983
  • Gender: Male
Re: Global blocks - or how to get the same content on every page
« Reply #41 on: October 04, 2009, 10:39:36 PM »
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:

Code: [Select]

                <!-- 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

  • Guest
Re: Global blocks - or how to get the same content on every page
« Reply #42 on: October 04, 2009, 11:09:22 PM »
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

Offline kweitzel

  • WebsiteBaker Org e.V.
  • **
  • Posts: 6983
  • Gender: Male
Re: Global blocks - or how to get the same content on every page
« Reply #43 on: October 05, 2009, 12:09:15 AM »
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

Offline Housy

  • Posts: 39
  • Gender: Male
Re: Global blocks - or how to get the same content on every page
« Reply #44 on: May 29, 2010, 08:40:50 PM »
if it does not work, try curl instead:

Code: [Select]
$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
« Last Edit: May 29, 2010, 08:42:42 PM by Housy »

Offline kweitzel

  • WebsiteBaker Org e.V.
  • **
  • Posts: 6983
  • Gender: Male
Re: Global blocks - or how to get the same content on every page
« Reply #45 on: May 29, 2010, 09:25:26 PM »
Have you tried the droplet sectionpicker instead?

cheers

Klaus

Offline Housy

  • Posts: 39
  • Gender: Male
Re: Global blocks - or how to get the same content on every page
« Reply #46 on: May 30, 2010, 01:00:32 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

Offline kweitzel

  • WebsiteBaker Org e.V.
  • **
  • Posts: 6983
  • Gender: Male
Re: Global blocks - or how to get the same content on every page
« Reply #47 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

Offline Housy

  • Posts: 39
  • Gender: Male
Re: Global blocks - or how to get the same content on every page
« Reply #48 on: May 31, 2010, 01:03:49 AM »
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
« Last Edit: May 31, 2010, 01:05:45 AM by Housy »

Offline kweitzel

  • WebsiteBaker Org e.V.
  • **
  • Posts: 6983
  • Gender: Male
Re: Global blocks - or how to get the same content on every page
« Reply #49 on: May 31, 2010, 08:16:38 AM »
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