Jump to content
pwired

Delayed output and another layout

Recommended Posts

Hi,
The more I use the delayed output strategy the more I like it. Load site wide used variables in _init.php, do your for each things and logic in the template file and output with _main.php

But besides that I am wondering what you guys are doing when another layout is needed for a page that needs something different.

Let's say I have a picture slider that I only want to use on the home page. On the contact page I only want to use the navigation banner and a contact form.

Now I can make an extra template file contact.php and an append file _contact.php. In the append file _contact.php I leave out the picture slider and instead add a contact form. I go to the backend file settings of contact.php and disable the automatic append of _main.php and select _contact.php instead.

Or I can keep on using _main.php using an include for either the picture slider or a contact form.
Put there some logic that looks on what page we are, and if we are on the contact page then include
the contact form else include the picture slider.

Is there a better way to approach this ?


 

Share this post


Link to post
Share on other sites

There is a easy way to enhance the delayed output methode that don't get to abstract...

my setting is based on a tipp from horst i think...

in my templates folder i've simple a new folder named site/templates/layouts/

and there i have special layout if needed.

in my _init.php:

//default layout for output
$myLayout 	= 'default';

in my _main.php:

//output layout for main page content
include("layouts/{$myLayout}.php");

while this code is placed where the whole complete content between header/menu and footer magic happens...all other stuff like columns or sidebars are maintained in the default layout for example:

//default layout is two column layout with right sidebar for submenu or article pages
echo $headerContent; //see _init.php - some heading stuff

//wrapper section and some space
echo '<section class="container page-content" >';
	echo '<hr class="vertical-space2">';

//start page content
echo '<section class="eleven columns">';
		echo $content;
echo '</section>';

//sidebar content
echo '    <aside class="four columns offset-by-one sidebar">';
		echo $aside;
echo '    </aside>';

//end wrapper
echo '    <hr class="vertical-space2">';
echo '  </section>';

or the full_page.php layout:

//default layout is two column layout with right sidebar for submenu or article pages
echo $headerContent; //see _init.php - some heading stuff

//wrapper section and some space
echo '<section class="container page-content" >';
	echo '<hr class="vertical-space2">';

//start page content
echo '<section class="sixteen columns">';
		echo $content;
echo '</section>';

//end wrapper
echo '    <hr class="vertical-space2">';
echo '  </section>';

and in the _template_ files i setup the content vars used in the layouts and overwright the layout setting if needed.

example basic-page.php where the user can set the aside sidebar on or off (optionfield full_page)...

//basic-page.php = normal page content

//render pagetable content - kind of blockbuilder for main content
if(count($page->pt_content)>0){
     foreach($page->pt_content as $l){
         $content .= $l->render();
     }
}

//page is with sidebar so we render Staff if it is set
if ($page->flag_fullpage == 0){ // 1 is checked, 0 is unchecked
	$aside .= renderStaff();
}

//set full_page layout if flag_fullpage is check on the default page template
if ($page->flag_fullpage == 1){ // 1 is checked, 0 is unchecked
	$myLayout = 'full_page';
}

so this is only one more layer to get different layouts for different or the same templates...

this is just a easy example - but if you use url segements for articles (root-page/year/month or root-page/tag) you could switch the layout for these...and so on.

i'm not the fan of making simple frontend layouts to abstract...so may this helps you forward.

Best regards mr-fan

  • Like 2

Share this post


Link to post
Share on other sites

@pwired: You should have a look to the SPEX module, it has all what you are looking for onboard allready.

  • Like 2

Share this post


Link to post
Share on other sites

Thanks everybody for your replies.

I already saw the wire render pattern passing by somewhere in the past in the forum but didn't realize then it was what I was looking for now. I prefer not to use a module at this moment and will try clsource's wire render pattern (well documented) and Horst's solution which I found again here in the forum https://processwire.com/talk/topic/8767-regarding-delayed-output/ also mentioned by mr-fan in this thread. I think these approaches will make the delayed output strategy for me a complete workflow for almost any website and speed up time to get things done and maintained.

  • Like 3

Share this post


Link to post
Share on other sites

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...