Appending content to end of document

I am making an widget that will output HTML. Some times this HTML will contain a form, and to avoid the widget to put this form into an existing form, I want the widget to append it’s content at the end of the body block.

(It is not important where in the DOM the content goes)

Is there any way to do this today in the framework?

OK, short explanation, how do I from within a component or widget append HTML to the end of the webpage, even when the widget or component is called early in the execution?

This was a hard thing to solve. But I will describe how I solved it, in case other have the same challange.

In my Controller class (which extends CController) i override function render() so that I could append the data I wanted before the layout was applied.

From the code you can tell i added a class array $this->appendToView with strings to append. This way I can append content from controller and views, and upon render that content is appended to the view content before layout:


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

	{

        	if($this->beforeRender($view))

        	{

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

                	

                	// This is the code we add to the render function here and which

                	// is not present in the parent::render() function. We do this

                	// to append content to the view before layout.

                	if (!empty($this->appendToView)) {

                    	$output .= "\n\n<!-- appending data to the view: -->\n";

                    	$output .= implode('', $this->appendToView);

                    	$output .= "\n<!-- finished appending data to the view -->\n";

                	}

                	

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

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

                	}

                	$this->afterRender($view,$output);


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


                	if($return)

                        	return $output;

                	else

                        	echo $output;

        	}

	}	

Not really built-in if you have to hack the core. :stuck_out_tongue: