PHP Classes

PHP Templater: Process and render templates similar to AngularJS

Recommend this page to a friend!
  Info   Documentation   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 72 All time: 10,240 This week: 488Up
Version License PHP version Categories
php-templater 1.0BSD License5HTML, PHP 5, Templates
Description 

Author

This package can process and render templates similar to AngularJS.

It can take a template string and an array with parameter values that will be used to process the template.

The package provides a base replacer interface that can be implemented by classes that define different means to find template marks with a syntax similar to AngularJS and replace the marks with values generated dynamically using context information based on the template processing parameters.

Picture of Till Wehowski
  Performance   Level  
Name: Till Wehowski <contact>
Classes: 30 packages by
Country: Germany Germany
Age: 45
All time rank: 107269 in Germany Germany
Week rank: 49 Up3 in Germany Germany Up
Innovation award
Innovation award
Nominee: 12x

Documentation

php-templater

This package can process and render templates similar to AngularJS.

Templates {{my.var}} for ['my'=>['var'=>'Hello, World']]

Examples

frdl\Templater\SimpleDotNotationReplacer

Based on regular expression.

$arr = [
    'test' => [
        'message' => 'Hello, World',
    ],

];


echo \frdl\Templater\SimpleDotNotationReplacer::replace(\frdl\Context::create($arr), 
    'Message: {{test.message}}');
    //Message: Hello, World

frdl\Templater\AdvancedReplacer

Based on https://github.com/wmde/php-vuejs-templating .

$arr = [
    'show' => false,
    'test' => [
        'message' => 'Hello, World',
    ],
    'items' => [
        [ 'property' => 'value1' ],
        [ 'property' => 'value2' ],
    ],
];


echo \frdl\Templater\AdvancedReplacer::replace(\frdl\Context::create($arr),   
  '<div>
     <h1 ng-bind="title"></h1>
     <p>Message: {{test.message}}</p>
     <p ng-show="show">this should be hidden</p>
     <p ng-if="!show">this should be visible</p>
     <p><a ng-repeat="item in items">{{item.property|ucfirst}}</a></p>
    
    </div>');
  
/*
//Renders to:  
<div>
     <h1><p>Template Test Title</p></h1>
     <p>Message: Hello, World</p>
     
     <p>this should be visible</p>
     <p><a>Value1</a><a>Value2</a></p>
    
    </div>

*/

  Files folder image Files (9)  
File Role Description
Files folder imagesrc (1 directory)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files (9)  /  src  
File Role Description
Files folder imagefrdl (1 directory)

  Files folder image Files (9)  /  src  /  frdl  
File Role Description
Files folder imageTemplater (6 files)

  Files folder image Files (9)  /  src  /  frdl  /  Templater  
File Role Description
  Plain text file AdvancedReplacer.php Class Class source
  Plain text file Component.php Class Class source
  Plain text file Replacer.php Class Class source
  Plain text file ReplacerInterface.php Class Class source
  Plain text file SimpleDotNotationReplacer.php Class Class source
  Plain text file Templating.php Class Class source

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:72
This week:0
All time:10,240
This week:488Up