DOMtempl

HTML templating that brings you peace

Documentation - PHP

Quick start

 
    include 'domtempl.php';
 
 

Reading the template

 
    $l = new DOMtempl('path/to/template.html');
 
 

or (not recommended)

 
    $l = new DOMtempl('<html><p data-var="foo"></p></html>', FRAGMENT);
 
 

Reading variables defined/expected by template

 
    $l = new DOMtempl('<html><p data-var="foo">Boo</p></html>', FRAGMENT);
 
    print_r($l->vars);
    //array('foo' => "Boo") 
 

Writing variables

 
    $l->assign("foo", "Hello world");
 
 

You can also assign variables by accessing the vars public property,

 
    $l->vars['foo'] = "Hello world";
 
 

has the same effect.

Writing output

 
    $l->out();
 
 

which is a shorthand for

 
    $html = $l->dump();
 
    echo $html;
 
 

Writing XML output

 
    echo $l->dumpXML();
    //or
    $l->outXML();
 
 

Same as above, but produces XML instead of HTML.

Complete example

 
    include 'domtempl.php';
    $l = new DOMtempl('<html><p data-var="foo">Boo</p></html>', DOMtempl::FRAGMENT);
    print_r($l->vars);
    //array('foo' => "Boo")
    $l->assign('foo', 'Moo'); 
    $l->out();
    //<html><p>Moo</p></html>