losthost/template-helper

There is no license information available for the latest version (v1.0.0) of this package.

A helper class to use php-templates

v1.0.0 2023-10-06 00:12 UTC

This package is auto-updated.

Last update: 2024-12-06 10:36:07 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();