Usage.

Install uTemplate.

In order to do that, simply copy the file uTemplate.php to your server and use require_once to include it in your code.

require_once "uTemplate.php";

Create an instance of the engine.

The uTemplate class uses the singleton pattern. This means you don't really need to instantiate it (although you may do it, but only if you really, REALLY have to). All you need to do is get a static instance of the engine:

$template = uTemplate::getInstance();

You may get the instance whenever you need in your code, and it will always be the same instance, so all settings vars and defined view scripts will be there.

Configure the engine.

The engine can be configured using the public methods it provides. Take a look at the API for detailed descriptions.

The intended setup includes at least two view scripts: layout and head. The layout is the content of the <body> tag. The head is the content of the <head> tag.

Additional view scripts can be defined and then rendered in the layout. Variables may also be passed to all view scripts. Finally, it's also possible to append or prepend any links, scripts, meta tags etc.

$template = uTemplate::getInstance();
$template
	->varAdd("foo",$foo)
	->layoutViewScript(PATH."/layout.php")
	->headViewScript(PATH."/head.php")
	->doctype(uTemplate::DOCTYPE_HTML5)
	->viewScriptAdd("nav",PATH."/nav.php")
	->viewScriptAdd("content",PATH."/main.php")
	->headScriptPrepend("/js/jquery.js")
	->footScriptAppend("alert('Awesome!');");

Render the view scripts.

Inside the view scripts, it's possible to render other view scripts. They can be nested in any way necessary. The most typical use of view script rendering is outputting the main content in the layout.

<h1>My awesome site</h1>
<?php echo $this->render("content"); ?>

Render the entire layout.

When everything is ready, rendering the HTML output is as simple as using the render method.

echo uTemplate::getInstance()->render();

Advanced use

For more sophisticated usage possibilities, please refer to the API to get a sense of what is possible with uTemplate!