Rendering dynamic text rather than a view file

Ok, this is a quick one, and a bit a laziness on my part maybe…

I want to render a view in an action (nothing unusual there), but instead of rendering a particular view file, I want to give the controller a chunk of text to render.

e.g.


public function actionIndex() {

    $this->render('<p>a piece of random text</p><?php echo "with some php thrown in for good ".$titbit; ?>', array('titbit' => 'measure'));

}

instead of


public function actionIndex() {

    $this->render('view', array('titbit' => 'measure'));

}

I know I could just do some echoing or evaling, but I don’t really like that, and I want to preserve the same structure with Yii wrapping the resulting evaluation in the appropriate layout file.

I have dug through CController and CBaseController chasing up the various different render methods, but can’t see any easy way to do this, so does anyone have any good suggestions for this?

what about

http://www.yiiframework.com/doc/api/1.1/CController#renderText-detail

Thanks - that looks perfect!

I can’t think why I didn’t see it before.

I’ll check it out, and confirm.

Hi there,

I used


$this->renderText("<?php echo 'sample dynamic text' ?>");

but dont work. sample dynamic text don’t print out.

The documentation says the renderText():

Is there a way for rendering dynamically?