Conditionally display

Hi,

i need a conditionally display content between beginWidget and endWidget. In widget`s class i have attribute $visible to store information about visibility. How can i get this value from view file? I have to use static function but then i can not use $this->visible.

Thanx

Quote

Hi,

i need a conditionally display content between beginWidget and endWidget. In widget`s class i have attribute $visible to store information about visibility. How can i get this value from view file? I have to use static function but then i can not use $this->visible.

Thanx

I 'think' this is what your talking about



<div id="mainmenu">


<?php $this->widget('application.components.MainMenu',array(


	'items'=>array(


		array('label'=>'Home', 'url'=>array('site/index')),


		array('label'=>'Contact', 'url'=>array('site/contact')),


		array('label'=>'Login', 'url'=>array('site/login'), 'visible'=>Yii::app()->user->isGuest),


		array('label'=>'Logout', 'url'=>array('site/logout'), 'visible'=>!Yii::app()->user->isGuest)


	),


)); ?>


</div>


That's right from the scaffolding.

Why you would use static variable?

Ok, i used static variable and work :) i not thought it would be so easy.

Too bad that i can not use the word "visible" in parameters to my widget.

I have error:

Quote

Property "Portlet.visible" is not defined.

00135:    public function createWidget($className,$properties=array())

00136:    {

00137:        $className=Yii::import($className,true);

00138:        $widget=new $className($this);

00139:        foreach($properties as $name=>$value)

00140:        $widget->$name=$value;

00141:        $widget->init();

00142:        return $widget;

00143:    }

But i used a different word as a parameter.

My question is still not answered: why you define visible as a static variable?

So, i would do a conditionally display content between beginWidget and endWidget in my widget, which has attribute visible. On the basis of this variable i show header and footer widget.



<?php $this->beginWidget('application.modules.portlet.components.Portlet',array(


	'id'=>'userInfo1',


	'title'=>'User info',


	'visible'=>true,   


	)); ?>





...body content that may be captured by the widget...





<?php $this->endWidget(); ?>





<?php $this->beginWidget('application.modules.portlet.components.Portlet',array(


	'id'=>'userInfo2',


	'title'=>'User info',


	'visible'=>false,   


	)); ?>





...body content that may be captured by the widget...





<?php $this->endWidget(); ?>


Problem is, when widget is invisible because the text “…body content that may be captured by the widget…” will still be displayed :(

So i did so:



<?php $this->beginWidget('application.modules.portlet.components.Portlet',array(


	'id'=>'userInfo2',


	'title'=>'User info',


	'visible'=>false,   


	)); ?>





<?php if(Portlet::$visibility): ?>


...body content that may be captured by the widget...


<?php endif; ?>





<?php $this->endWidget(); ?>


where variable $visibility is static variable.

Maybe this solution is not good but works. I solved my problem in this way, because i don`t know how to do capture body by the widget.

In post http://www.yiiframew…72.html#msg5172 you write that i can use ob buffer to capture the body content or alternatively, i can extend COutputProcessor.

Unfortunately i could not do so.

Maybe you would find some time to write an example how to do capture body by the widget.