thephpleague / plates

Native PHP template system
https://platesphp.com
MIT License
1.47k stars 180 forks source link

nested inheritance #8

Closed mindyk closed 10 years ago

mindyk commented 10 years ago

is this possible / intented, i am trying right now and get a blank page without erros )- :

<!-- index -->
<?= $this->content ?>
<!-- AAA -->
<?php $this->layout('index') ?>
<?php $this->start('content') ?>
<h1>CONTENT</h1>
<?= $this->subcontent ?>
<?php $this->end();
<!-- BBB -->
<?php $this->layout('AAA') ?>
<?php $this->start('subcontent') ?>
<h2>SUBCONTENT</h2>
<?php $this->end(); ?>

expected output

<!-- index -->
<h1>CONTENT</h1>
<h2>SUBCONTENT</h2>
reinink commented 10 years ago

You cannot define "sub layouts". In fact, if you set a layout using the $this->layout() method in a nested template it will actually overwrite the layout defined by it's parent.

Here is how I would tackle what your trying to do. In this situation aaa is your template, index is the layout, and bbb is the nested template.

<!-- index -->
<?=$this->content?>
<?=$this->subcontent?>
<!-- AAA -->
<?php $this->layout('index') ?>

<?php $this->start('content') ?>
    <h1>CONTENT</h1>
<?php $this->end() ?>

<?php $this->start('subcontent') ?>
    <?php $this->insert('bbb') ?>
<?php $this->end() ?>
<!-- BBB -->
<h2>SUBCONTENT</h2>
reinink commented 10 years ago

@mindyk, you may be interested to know that layout stacking (or sub layouts) are now possible in dev-master, coming soon to Plates version 2.0. See issue #10 for more details.