Dynamic Blocks and Template Inheritance

Hello Yii2-Core Team

I read some interesting discoussion in github in the yii2 project.

There I saw following idea:

<?php $this->inherits('product.php'); // automatically passes current scope data to product.php ?>

<?php $this->beginBlock('specs')?>

    <?= $this->parent() // outputting content of the block from the view mentioned in ->inherits() ?>

    <div>5 year warranty included!</div>

<?php $this->endBlock()?>

<?php $this->beginBlock('description')?>

    <?= $phoneDescription // totally replacing content ?>

<?php $this->endBlock()?>

This kind of syntax would make the layout-view management in Yii so much more flexibel. Do you maybe consider to add this feature in one of the next versions of yii2?

Thank you

I remember that. It was discussed long time ago and it was denied because of implementation complexities.

I understand.

I was also thinking, how a solution could be.

Maybe this idea could be considered again, with

fresh ideas and inspirations? Is it a yii2 specific

issue, what would make the implementation complex?

How is it "twig" or "blade" doing? In the end, they also

have to convert their syntax to plain php.

Best regards


Both twig and blade have pre-processing in order to be converted to PHP. Native PHP templates in Yii are processed as is.