dinis
(Dinislage)
July 12, 2010, 6:16pm
1
Hello,
I’ve been battling in order to share a partial view across multiple controllers .
Does anyone know what’s the best way to do this?
I’ve tried specifying the whole path in the renderPartial method with no success and the possible solution I’ve come to is to make Widgets for those views. I think using widgets is a bit overkill…
Searching here and Google didn’t lead me to nothing related to what I want.
Thanks in advance.
andy_s
(Arekandrei)
July 12, 2010, 6:25pm
2
Path in the following format must work fine:
application.views._myPartialView
dinis
(Dinislage)
July 12, 2010, 6:31pm
3
Thanks. Probably messed up while trying that at first. All good now.
I was looking for the same stuff.
So I put _topmenu.php partial in the /protected/views/layouts/_topmenu.php
and in the layout I wrote <?php echo $this->renderPartial(‘application.views.layouts._topmenu’); ?>.
That made my partial to work globally.
Nice. Thanks.
zaccaria
(Matteo Falsitta)
November 17, 2010, 9:04am
5
If you want to include a part of the layout, this is a good method.
If you want to share a view among controllers (like some partial form) is better to create a widget.
oceatoon
(Oceatoon)
August 11, 2011, 4:45am
6
zaccaria:
If you want to include a part of the layout, this is a good method.
If you want to share a view among controllers (like some partial form) is better to create a widget.
using widgets works well, thx
but isn’t there a way to use renderPartial in a global way
$this->renderPartial(Yii::getPathOfAlias('application.views.layouts.myPartialview'))
I’m still curious to get the code above working in a global way , cross controller and modules
but I didn’t get it to work
can any one see what I might be doing wrong ?
Regards
andy_s
(Arekandrei)
August 11, 2011, 6:43am
7
using widgets works well, thx
but isn’t there a way to use renderPartial in a global way
$this->renderPartial(Yii::getPathOfAlias('application.views.layouts.myPartialview'))
I’m still curious to get the code above working in a global way , cross controller and modules
but I didn’t get it to work
can any one see what I might be doing wrong ?
Regards
Try this?
$this->renderPartial('application.views.layouts.myPartialview');
// or
$this->renderPartial('//layouts/myPartialview');
oceatoon
(Oceatoon)
August 12, 2011, 6:58am
8
Thanks Andy strangely this time around it worked,
I probably misstyped something