Thursday, November 12, 2015

PHP - Render partial view within another controller's view

Goal:
Render a view called view_B within another view called view_A.  Note that view_B belongs to a different controller than view_A and thus is in a different directory.

Solution:
Put this within view_A's code, where "site" is the directory of view_B within the "views" directory and "dashmenu" is the name of view_B.

<?php echo $this->render('//site/dashmenu'); ?>

aka, generically:

<?php echo $this->render('//view_B_Directory/view_B'); ?>

Note that the "//" double slash here denotes the path is within the views directory.


There is also a more verbose way to do this:
<!-- a more verbose way -->
<?php echo Yii::$app->view->render('//site/dashmenu'); ?> 

No comments:

Post a Comment