frdl / php-templater
Template Replacers (`Angular-style`)
Fund package maintenance!
wehowski
webfan.de/sponsor-me
domainundhomepagespeicher.de
Requires
- php: >=7.2.0
- frdl/context: >=0.0.4
- wmde/php-vuejs-templating: ^1.0.1
This package is auto-updated.
Last update: 2024-12-04 17:36:04 UTC
README
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> */