How to reuse a view?

Hi, i use the same view in three sections of my site, but each section needs to make some changes in view, eg.




<?php

$this->breadcrumbs=array(

	Yii::t('news','Create new'),

);

?>


<?php $form=$this->beginWidget('CActiveForm', array(

		'htmlOptions'=>array('enctype'=>'multipart/form-data'),

));?>


<div class="row">

        <?php echo $form->labelEx($model,'title'); ?>

        <?php echo $form->textField($model,'title',array('size'=>50,'maxlength'=>150)); ?>

        <?php echo $form->error($model,'title'); ?>

    </div>


<div class="row buttons">

		<?php echo CHtml::submitButton($model->isNewRecord ? Yii::t('news','Create') : Yii::t('news','Save')); ?>

	</div>

    

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



In another section i need:




<?php

$this->breadcrumbs=array(

	Yii::t('news','Create new'),

);

?>


<?php $form=$this->beginWidget('CActiveForm', array(

		'htmlOptions'=>array('enctype'=>'multipart/form-data'),

));?>


<div class="row">

        <?php echo $form->labelEx($model,'title'); ?>

        <?php echo $form->textField($model,'title',array('size'=>50,'maxlength'=>150)); ?>

        <?php echo $form->error($model,'title'); ?>

    </div>


<div class="row">

<?php echo $form->checkBox($model, 'permissions'); ?>

</div>


<div class="row buttons">

		<?php echo CHtml::submitButton($model->isNewRecord ? Yii::t('news','Create') : Yii::t('news','Save')); ?>

	</div>

    

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



I do not want to repeat the same view in each section, is there anything similar to beginContent for this?

Thanks.

You can create a widget for share views among sections, but this is not the case.

I’d better repeat the code in this case.

I would create a widget with some conditional code in the view.

If you’re using that permissions checkbox in a controller, simply make it show if the controller id is like whatever controller it is.

Or based on actions…

I often use project-specific widgets to reduce typing. Don’t see anything wrong with that.

It keeps the views clean.