A really simple HTML template class for PHP. Be aware that it's still in development and features are subject to change, no warranty is given or implied.
Basically, this class enables you to load HTML based template markup, replace keywords, split the template, and output the markup
When loading a template, an array of keywords to be replace is passed into the method. The array should look something like this:
$keywords = array('THISKEYWORD' => 'This value will be displayed');
THISKEYWORD will be usable in your HTML markup as [TPL8_THISKEYWORD].
You can either load your markup from a file or by passing in a string from memory.
To load a template from a file, you can use from_file, like so:
$split = true;
$main_template = templ8::from_file('templates/default.html', $keywords, $split);
To load a template from a string in memory, you can use from_string, like so:
$main_template = templ8::from_string('<h1>[TPL8_THISKEYWORD]</h1>', $keywords);
THISKEYWORD will be usable in your HTML file as [TPL8_THISKEYWORD].
If you'd like to use a prefix other than TPL8_, you can specify a different prefix like so:
$template = templ8::from_file('template.html', $keywords, $split, 'TP_');
// or
$template = templ8::from_string('...', $keywords, 'TP_');
Splitting the template involves splitting the HTML markup into an upper and lower portion using the [TPL8_SPLIT] keyword. Typically you would place this keyword in the HTML file where you would like to put the content, then output the upper template portion, your content and then the lower portion of the template.
You can split the template by specifying $split = true in the constructor.
It's a good idea to check if the current template is splittable, so use this variable to check:
$main_template->_can_split;
Then you can manually split the template using this function:
$main_template->split_template();
Once the template has been automatically or manually split, you can output the template as a whole, or by outputing the top and bottom parts separately, as described in the next part.
You can tell the template to output using this function:
$main_template->output();
If you want to just get the markup, use:
$markup = $main_template->get_markup();
If you've split the template, you can use these functions:
$main_template->output_upper(); // output everything above the split keyword
// Put your content here
$main_template->output_lower(); // output everything below the split keyword
And there you have it. Simple, quick, fun.