Skip to content

awsmug/lib-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Awesome Lib - Template

Template helper classes.

Installation

Run the installation with composer.

composer require awsmug/lib-template:dev-develop

Howto

Text Template

Use of TextTemplate class:

$template = 'Hello {name}!';

$values = ['name' => 'John'] ;

$content = TextTemplate::init( $template, $values )->render();

Template file

Content in template.txt:

Hello {name}!

Use of TemplateFile class:

$template_file = 'template.txt';

$values = ['name' => 'John'] ;

$content =  TemplateFile::init( $template_file, $variables )->render();

PHP Template file

Simple variant

Content in Template.php:

<?php

echo 'Hello {name}!'

Use of PhpTemplateFile class:

$template_file = 'template.php';

$values = ['name' => 'John'] ;

$content =  PhpTemplateFile::init( $template_file, $values )->render();

Variant with PHP variables

Content in Template.php:

<?php for( $i = 0; $i < $variables['count']; $i++  ): ?>
    {content}
<?php endforeach; ?>

Use of PhpTemplateFile class:

$template_file = 'template.php';

$values = ['content' => 'This is my content'] ;

$variables = [ 'count' => 5 ];

$content =  PhpTemplateFile::init( $template_file, $values, $variables )->render();

Setting delemiters

By default delimiters for variables are '{' and '}'. You can change this with the method method setDelimiters( $openDelemiter, $closeDelimiter ) in all Template classes.

$template = 'Hello [name]!';

$values = ['name' => 'John'] ;

$content = TextTemplate::init( $template, $values )->setDelimiters('[',']')->render();

About

Awesome text template library

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages