plates
plates copied to clipboard
Passing data to insert() inside layout()
Demo structure:
/layouts
main.php
/partials
sidebar.php
index.php
I "extend" layouts/main.php from index.php, how do I change something like a heading inside sidebar.php from index.php?
Update: I'm currently passing data from index up to layouts/main & down to partials/sidebar in a similar fashion to the stacked layouts in the docs, which feels a bit like prop drilling. Wondering if that's the optimal way.
Hey! I hope you were able to use plates in your project. Here's an example of how I'm using it. The home.php view calls the head.php file which is in the "html" folder in the root directory used by plates.
I'm just using $this->insert and $this->section See the example code:
// plates config
$templates = new Engine();
$templates->setDirectory($path);
return $templates->render($this->page, $this->templateData);
// home.php
<?= $this->insert('_html/head', ['title' => 'page title' ]) ?>
<?= $this->insert('_html/head') ?>
// head.php
<?= $this->section("content") ?>
<!DOCTYPE html>
<title><?=$this->e($title)?></title>