This repository has been archived on 2024-06-20. You can view files and clone it, but cannot push or open issues or pull requests.
peryoudow/vendor/league/plates/docs/templates/nesting.md
2020-01-06 14:23:12 +01:00

1,013 B

layout permalink title
default templates/nesting/ Nesting

Nesting

Including another template into the current template is done using the insert() function:

<?php $this->insert('partials/header') ?>

<p>Your content.</p>

<?php $this->insert('partials/footer') ?>

The insert() function also works with folders:

<?php $this->insert('partials::header') ?>

Alternative syntax

The insert() function automatically outputs the rendered template. If you prefer to manually output the response, use the fetch() function instead:

<?=$this->fetch('partials/header')?>

Assign data

To assign data (variables) to a nested template, pass them as an array to the insert() or fetch() functions. This data will then be available as locally scoped variables within the nested template.

<?php $this->insert('partials/header', ['name' => 'Jonathan']) ?>

<p>Your content.</p>

<?php $this->insert('partials/footer') ?>