Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing data to insert() inside layout() #325

Open
zaxwebs opened this issue Dec 12, 2023 · 2 comments
Open

Passing data to insert() inside layout() #325

zaxwebs opened this issue Dec 12, 2023 · 2 comments

Comments

@zaxwebs
Copy link

zaxwebs commented Dec 12, 2023

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?

@zaxwebs
Copy link
Author

zaxwebs commented Dec 12, 2023

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.

@t-hauck
Copy link

t-hauck commented Jun 24, 2024

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>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants