Partial Render in field value


I am having a strange requirement, I have a content page , its value come from the database which I display in a view. Now, within the content, I have a listing of products to be done, and I tried to call the renderpartial, but since I have the field value echo in the view, renderpartial code do not get executed. Is there a way I can display the content and have the content from renderpartial executed ?

in my view i am doing like this

<?php echo $model->ContentField; ?>

in My Content (coming from database)

I have


<?php $this->renderpartial(‘application.views.common._view’,array(‘code’=>‘XX’)) ?>


Looking for some guidance.

i think you need to use here the "eval" function for example:

echo eval($model->ContentField);

but this function is very dangerous so the better solution is to use some render engine for example Smarty, or just create pattern and use st_replce or preg_replce

This is an interesting read from SO:

If I understood fine your case, maybe the error is that you are not passing the model in the array,

your call will be:

public function actionSomeAction() {

   $model = new MyProduct();  // or find it via:  MyProduct::model()->findByAttributes(array('articleid'=>'XX'))

   $model->contentField = "some value";


    // PUT MODEL, and CODE, in order to get this variables from inside _view.php, if dont, an error occurs.

    $this->renderpartial('application.views.common._view',array('code'=>'XX',  'model'=>$model)) ;


I agree with haimwd. Avoid the eval function whenever you can.

If you have the string:

<?php $this->renderpartial('application.views.common._view',array('code'=>'XX')) ?>

in your database, try to see if it is really necessary for what you want or if it would be enough to put just the value of ‘code’ in the database and then insert the value as parameter in the renderPartial call.