peryoudow/vendor/league/plates/docs/templates/inheritance.md

1.8 KiB

layout permalink title
default templates/inheritance/ Inheritance

Inheritance

By combining layouts and sections, Plates allows you to "build up" your pages using predefined sections. This is best understand using an example:

Inheritance example

The following example illustrates a pretty standard website. Start by creating a site template, which includes your header and footer as well as any predefined content sections. Notice how Plates makes it possible to even set default section content, in the event that a page doesn't define it.

template.php
~~~ php <html> <head> </head>
section('page')?>
section('sidebar')): ?> section('sidebar')?> fetch('default-sidebar')?>
</html> ~~~

With the template defined, any page can now "implement" this layout. Notice how each section of content is defined between the start() and end() functions.

profile.php
~~~ php layout('template', ['title' => 'User Profile']) ?> start('page') ?>
<h1>Welcome!</h1>
<p>Hello <?=$this->e($name)?></p>
stop() ?> start('sidebar') ?>
<ul>
    <li><a href="/link">Example Link</a></li>
    <li><a href="/link">Example Link</a></li>
    <li><a href="/link">Example Link</a></li>
    <li><a href="/link">Example Link</a></li>
    <li><a href="/link">Example Link</a></li>
</ul>
stop() ?>