correct use of widgets??!!??!!

good morning, I have a problem with the widgets and smarty …

I am not able to display the widget where I want to show it.

smarty is my version:Smarty 3.1.7 Released

my yii framework is:v1.1.9

and smarty-renderer :v1.0.2

I have a tpl file where I have the call to the widget:


<div class="container" id="page">

	<div id="header">

		<div id="logo">{$PageName}</div>

	</div><!-- header -->


	<div id="mainmenu">

            <ul id="yw0">

                {foreach $Menu as $pack}

                    <li><a href="{$pack.url}">{$pack.label}</a></li>



	</div><!-- mainmenu -->





	<div class="clear"></div>

and php file:


$smarty = new Smarty();





the error I get is:

PHP notice

Undefined index: this


73                 <?php  $_smarty_tpl->tpl_vars['pack'] = new Smarty_Variable; $_smarty_tpl->tpl_vars['pack']->_loop = false;

74  $_from = $_smarty_tpl->tpl_vars['Menu']->value; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array');}

75 foreach ($_from as $_smarty_tpl->tpl_vars['pack']->key => $_smarty_tpl->tpl_vars['pack']->value){

76 $_smarty_tpl->tpl_vars['pack']->_loop = true;

77 ?>

78                     <li><a href="<?php echo $_smarty_tpl->tpl_vars['pack']->value['url'];?>

79 "><?php echo $_smarty_tpl->tpl_vars['pack']->value['label'];?>

80 </a></li>

81                 <?php } ?>

82             </ul>

83     </div><!-- mainmenu -->


85         <?php echo $_smarty_tpl->tpl_vars['this']->value->widget('zii.widgets.CBreadcrumbs',array('links'=>$_smarty_tpl->tpl_vars['this']->value->breadcrumbs),true);?>





90     <?php  $_smarty_tpl->tpl_vars['pack'] = new Smarty_Variable; $_smarty_tpl->tpl_vars['pack']->_loop = false;

91  $_from = $_smarty_tpl->tpl_vars['migas']->value; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array');}

92 foreach ($_from as $_smarty_tpl->tpl_vars['pack']->key => $_smarty_tpl->tpl_vars['pack']->value){

93 $_smarty_tpl->tpl_vars['pack']->_loop = true;

94 ?>

95             <?php  $_smarty_tpl->tpl_vars['rest'] = new Smarty_Variable; $_smarty_tpl->tpl_vars['rest']->_loop = false;

96  $_from = $_smarty_tpl->tpl_vars['pack']->value; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array');}

97 foreach ($_from as $_smarty_tpl->tpl_vars['rest']->key => $_smarty_tpl->tpl_vars['rest']->value){

this is what I have and I can not use this widget,I am lost with the use of widgets and I do not get advance.

can help me ?

thank you very much!

Wow!!! I’m stupid…

I only need one line in the php file


and tpl file:


but this way seems very dirty

Do I always am obliged to send all the "$ this"?

Could I make this choice?

in php file



$variable = ob_get_clean();  


and tpl file:


so I am not obliged to send all "$ this"

Is cleaner than this?

You should not use Smarty yourself. This is done by smarty viewRenderer.

You first have to add SmartyViewRenderer to your application config as described in the readme.

Then you can simply render your template in a controller action just as you do it with normal views:

in the template $this refers to the current controller rendering the template so it has to be:


to render a widget.

You do not need to create a Smarty object and you do not need to assign anything to it. Template variables are assigned by giving them as second parameter array to the render()-method.