Skip to content

What layout does ​

include is ideal when you assemble shared fragments by hand. layout goes further: one shared wrapper can wrap every page automatically.

Step 1: define a shared layout ​

Create app/home/view/public/layout.html:

html
<html>
    <head>
        <script src='...js'></script>
        <link href='...css'/>
    </head>
    <body>
        <!-- slot for page body -->
        {__LAYOUT__}
    </body>
</html>

Step 2: page-only content ​

Example app/home/view/index/docs.html:

html
Page body
{$content}

Step 3: enable layout in config ​

In app/config.php:

php
<?php
return array(
    'db_host' => 'localhost',
    // …
    'layout' => 'public:layout',
);

Rendered output ​

With layout enabled, the page template replaces {__LAYOUT__} in the layout:

html
<html>
    <head>
        <script src='...js'></script>
        <link href='...css'/>
    </head>
    <body>
        Page body
        {$content}
    </body>
</html>

Summary ​

After layout is configured, each page only authors its own content; shared head and foot are applied automatically.

The important piece is the layout entry in app/config.php.

PhpTide documentation