Jump to content

_main.php inflexibility


pwnewbie
 Share

Recommended Posts

When you do a delayed output with _main.php what if you have a very specialized page that is totally different from _main.php, then I would have to restructure _main.php into more regions or do a lot of conditionals? Would tying a template to its own _main.php (the chrome) be a better approach? That means each template can decide which _main.php to use.

Link to comment
Share on other sites

Create another template to those pages and edit the template. Then go to the Files tab and specify another file in the "Append file" section.

post-3156-0-65675300-1444934018_thumb.pn

Plus you may need to tick the checkbox to disable automatic appending of _main.php.

  • Like 4
Link to comment
Share on other sites

Have a look to the module SPEX. This is a very comfortable, more advanced and flexible ready to use system for that. It already has all the functionality for as many of layout-templates, Slots and more as you want to use. It is in the modules directory, the author is Jonthan Dart. :)

Link to comment
Share on other sites

How many pages in your website are going to be different from all the other pages ? Usually the homepage will look different, or maybe the page that holds a contact form or you want the page with a guestbook to look different, etc. These are only a few examples. So usually no more than 3 or 4 pages will work or look different from all the other pages. I would not use a single _main.php for this filled with all the api/php code/logic to output the different functioning/looking website pages. I find it much more easy to use a template file for each different functioning/looking page but with each less needed api/php code. To stay with the examples this would be:  _home.php _contact.php _guestbook.php and the _main.php for all the other pages in the website. This is still a very easy way to do future maintenance on your website which is the idea behind the delayed output strategy.

Link to comment
Share on other sites

In my _main.php files I typically include a "layout" variation file. This is what you would start with as the main template, but moved outside to allow more customisation and flexibility. Specify a default layout to use in the _init.php file, and overwrite it in your template files as and when necessary.

_main.php

<html>
<head>
    <style></style>
    ...
</head>
<body>
    <header class="header">...</header>
    <section class="main"><?php require "./includes/layouts/{$layout}.php"; ?></section>
    <footer class="footer">...</div>
</body>
</html>

_init.php
 

$layout = 'default';    // specify a layout that would be used for "most" pages (I call mine default)

So most sites might have default, home and contact layout varieties as a starting point. A layout would include the stuff that varies between page designs and you would create as few or as many as you need, and call on the variables set by the template.

For example, layouts/contact.php:

<section class="content">
    <p>This is our address</p>
    <?= $page->body ?>
</section>
<aside>
    <iframe class="map">...</iframe>
</aside>
  • Like 9
Link to comment
Share on other sites

If there is a need to have more than one _main.php

I just create another one. Ex _main.php, _main_admin.php, _main_user.php

_init.php

$fileToRender = '_main_user';

config.php

$config->prependedFile = '_init.php';
$config->appendedFile = '_main.php';

home.php (example template)

if($user->isSuperuser()) {
   $fileToRender = '_main_admin';
}

_main.php


require_once '_header.php';

echo wireRenderFile($fileToRender);

require_once '_footer.php';

  • Like 2
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...