Yii2: Partial View Examples

Yii2: Partial View Examples

Last updated:

Yii 2 has a slightly different approach from Yii 1.x when it comes to rendering views inside views (or partials views).

Remember that, in Yii 2, $this in a view refers to a View object (not a controller) and it just so happens that Class View also has a render method and you can call it in your view, nesting views indefinitely.

//this is a view file
$this->title = 'ze Title';

<div class="bar baz">
    <!-- just like you would in a controller -->
    <?= $this->render( 'other_view', ['param'=> $some_var] ); ?>

Dialogue & Discussion