K
K
Ken Jee2016-08-30 19:47:45
Yii
Ken Jee, 2016-08-30 19:47:45

How to connect another template inside a template in Yii2?

How to connect another template inside a template in Yii2? Surely there is some kind of "directive" like include? Read the documentation. But didn't get in a bit. Essence: in a template to be used "subtemplate".

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Elena Stepanova, 2016-08-30
@Machez

www.yiiframework.com/doc-2.0/guide-structure-views...
1. Sub-template can be rendered

$this->render('another_template',['prop'=>$val]);//шаблон в этой же директории
$this->renderFile('@app/some/path/views/another_template',['prop'=>$val]);//шаблон из другого места

2. www.yiiframework.com/doc-2.0/guide-structure-views...
<?php $this->beginContent('@app/views/layouts/base.php'); ?>
 //Some another content - внедрение в вывод контента вызываемого layout 
<?php $this->endContent(); ?>

3. You can use blocks in layouts for post-embedding into the structure
www.yiiframework.com/doc-2.0/guide-structure-views...

A
Andrew, 2016-08-30
@mhthnz

In a view, the subtemplate must be in the same folder as the current view.

<?= $this->render('subtemplate', [
        'var' => $var,
    ]) ?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question