Render just plain html

How can i run just a simple function or something like a class member to add text or html code into the layout content.

For example, Currently to display something i can only use

render functions to load a file or rendertext to insert text.

The problem is that both inserts the entire layout with them. Is there any way to just add a text into the content?

For example:

If i want to display the content of the page.php file from my views directory i would do:

$this->render(‘page’, array());

If i need to add something above the contents of the page.php file i will either need to add it into the page.php file or using the renderpartial function to return the output and pass it in to the page.php file as a variable.

What i would like to do is:

$this->output .= "some text above the page.php file";

$this->render(‘page’, array());

this will output first the "some text above the page.php file" and the the contents of the page.php file from the render function.

Unfortunately something like this is not possible with Yii.

Any ideas on how to achieve something like this?

Thanks.

How about using a portlet. A portlet can be used elsewhere other than a left or right column. Then you can store text, notifications, messages, etc. in a database table and conditionally display the strings.

Jonah’s Skelton applications stores all text in a database table. This might give you some ideas.

What about using clips?

http://www.yiiframework.com/doc/api/1.0.10/CBaseController#beginClip

e.g. in your layout you can check the existance of a clip and output the clip

Bad approaches, I don’t know when and where i will be using this class member so clips or portlets are no good. I am still struggling to achieve this so if there are any other ideas i will appreciate you letting me know about them.

I think it would be more or less easy to create an extended version of CController which supports an output variable. Check out the render function, seems easy to modify:


	public function render($view,$data=null,$return=false)

	{

		$output=$this->renderPartial($view,$data,true);

		if(($layoutFile=$this->getLayoutFile($this->layout))!==false)

			$output=$this->renderFile($layoutFile,array('content'=>$output),true);


		$output=$this->processOutput($output);


		if($return)

			return $output;

		else

			echo $output;

	}

Or maybe modfiy processOutput() function.

Yes, Probably will be the easiest way, Will look into it.