Jump to content

regarding Delayed Output


adrianmak
 Share

Recommended Posts

https://processwire.com/docs/tutorials/how-to-structure-your-template-files/page4

I read from the documentation about delayed output.

The example given in the doc. all pages are outputted to main.inc. On other words,all pages layout are fixed in main.inc.

If I have a specific page which use different layout, how that page to use another page layout with delayed output strategy?

Link to comment
Share on other sites

main.inc should keep the largest possible code for all your different layouts and include sub-xy.inc files.

Lets say for example you have the default layout with $bodycopy and $sidebar and additionally a onecolumn layout without sidebar:

You define a new variable e.g. $myLayout:

// here is how it would look like in the /site/templates/init.inc

<?php
$headline = $page->get("headline|title"); 
$bodycopy = $page->body; 
$sidebar = $page->sidebar;
$myLayout = "default"; // we only write the name without the fileextension, this way we also can set a CSS-class in the body tag!

// or you put it into the head of every template file, here: /site/templates/basic-page.php

<?php
$headline = $page->get("headline|title"); 
$bodycopy = $page->body . $page->comments->render();
$sidebar = $page->sidebar;
$subnav = $page->children; 
$myLayout = "default";
include("./main.inc"); 

Now move the smallest possible segment from your main.inc into default.inc and replace it in main.inc with an include("./$myLayout"):

/site/templates/main.inc

<html>
  <head>
    <title><?php echo $headline; ?></title>
  </head>
  <body class="<?php echo $myLayout;?>">

  <?php include("./{$myLayout}.inc"); ?>
  
</body>
</html>
/site/templates/default.inc

    <div id='bodycopy'>
      <h1><?php echo $headline; ?></h1>
      <?php echo $bodycopy; ?>
    </div>
    <div id='sidebar'>
      <?php 
      echo $sidebar
      if(count($subnav)) {
        echo "<ul class='nav'>";
        foreach($subnav as $child) {
          echo "<li><a href='$child->url'>$child->title</a></li>";
        }
        echo "</ul>";
      }
      ?>
    </div>

Lets say you don't want the sidebar on your homepage, then you define / overwrite in your /site/templates/home.php the $myLayout var with

$myLayout = "onecolumn";

// we only write the name without the fileextension, this way we also can set a CSS-class in the body tag!

Create a file called "onecolumn.inc" and put in your desired markup, e.g.:

/site/templates/onecolumn.inc

    <div id='bodycopy'>
      <h1><?php echo $headline; ?></h1>
      <?php echo $bodycopy; ?>
    </div>

To stile your onecolumn layout with CSS you need to append to your css something like:

body.onecolumn div#bodycopy {
    width: 100%;
}
  • Like 11
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...