PHP code example of frdl / php-templater

1. Go to this page and download the library: Download frdl/php-templater library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

frdl / php-templater example snippets


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

];


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

$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>

*/