losthost / template-helper
A helper class to use php-templates
Installs: 36
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/losthost/template-helper
Requires (Dev)
- phpunit/phpunit: 10.3.5
This package is auto-updated.
Last update: 2025-10-06 12:31:40 UTC
README
Loads and displays or processes a template file
Very simple usage
use losthost\templateHelper\Template;
$template = new Template('template-file.tpl');
$template->display();
This will display the content of file templates/default/template-file.tpl
.
It seems not very usefull, so you can create more complex templates as in next example.
More complex usage
Create a template file ex. templatex/default/simple-template.tpl
with code:
Hello <?=$name; ?>!
Now to display "Hello John!" do the following:
use losthost\templateHelper\Template;
$template = new Template('simple-template.tpl');
$template->assing('name', 'John');
$template->display();
Multilang usage
Use $template = new Template('template.tpl', 'de');
to use templates in templates/de/
instead of templates/default/
.
You can change default templates dir from templates/
to anydir/
you want by using
$template->setTemplateDir('anydir')
Do not display output
Sometimes you don't want to display output. You may need just to get the template output for further processing. Use this:
$result = $template->process(); // insead of $template->display();