Some time ago, I created some methods to manipulate and render various pieces of an html document. It’s evolved into a pseudo document model. Originally written for CodeIgniter, I've refactored it for FuelPHP.
Here an example of working with the page title:
Document::set('title', 'My Site');
// then somewhere else you can do this
Document::append('title', 'My Site');
//then in the view
echo Document::render('title');
// and get this
<title>My Site : Page 2</title>
// you can also prepend a value
Document::prepend('title', 'Some Text');
// set the title separator like this
Document::set('separator', ' :: ');
Here's an example of rendering the DTD:
// in a controller or anywhere else
Document::set('doctype', 'xhtml11');
//then in the view
echo Document::render('dtd');
// or you can do this
echo Document::render('dtd', 'xhtml11');
// or this
echo Document::render('doctype', 'xhtml11');
How about rendering a complete html opening tag:
echo Document::render('htmlopen');
// to get this based on the doctype, language, and direction
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" dir="ltr">
The following Asset methods are wrapped: css, js, and img
// See the FuelPHP documentation for more information
// to add a stylesheet
Document::css('mycss.css');
// to render stylesheets
echo Document::css();
You could use it as a global registry:
// create a global variable
Document::set('myVar', 'myValue');
// access the global variable
$myVar = Document::get('myVar');
Create a container as an array and append/prepend value:
// Create the container
Document::set('myBucket', array());
// add some values to the container
Document::append('myBucket', 'myValue1');
Document::append('myBucket', 'myValue2');
// prepend a value to the container
Document::prepend('myBucket', 'myValueA');
For more information, see the inline documentation.