PHP code example of hokoo / templater
1. Go to this page and download the library: Download hokoo/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/ */
hokoo / templater example snippets
use iTRON\Templater\Templater;
$templater = new Templater();
$html = <<<TEMPLATE
<div class="popup %s" data-popup="%s">
<div class="title">
%s
</div>
<div class="content">
%s
</div>
</div>
TEMPLATE;
return $templater->render( $html, [
'class-foo',
'bar',
'The Best Title',
'Anything you want'
] );
$html = <<<TEMPLATE
<div class="popup %1$s" data-popup="%2$s">
<div class="title">
%3$s
</div>
<div class="content">
%4$s
</div>
</div>
TEMPLATE;
$html = <<<TEMPLATE
<div class="popup %s" data-popup="%s">
%s
[[repeater_tag_name]]
<div class="title">
%s
</div>
<div class="content">
%s
</div>
[[/repeater_tag_name]]
</div>
TEMPLATE;
return $templater->render( $html, [
'class-foo',
'bar',
[
[ 'tag' => 'repeater_tag_name', 'data' => [ 'The Best Title', 'Anything you want.' ] ],
[ 'tag' => 'repeater_tag_name', 'data' => [ 'There is no title', 'There is no content.' ] ],
]
] );
$html = <<<TEMPLATE
<div class="popup %1$s" data-popup="%2$s">
%3$s [[item]]
<div class="item">
<div class="title">%1$s</div>
<div class="content">
%2$s
[[button]]
<button id="%s">
%s
</button>
[[/button]]
</div>
</div>
[[/item]]
</div>
TEMPLATE;
$item_1 = [
[ 'tag' => 'button', 'data' => [ 'button-1', 'Tap me' ] ],
[ 'tag' => 'button', 'data' => [ 'button-2', 'Do not tap me' ] ],
];
$item_2 = [
[ 'tag' => 'button', 'data' => [ 'button-3', 'I ain\'t a button' ] ],
[ 'tag' => 'button', 'data' => [ 'button-4', 'Ok' ] ],
];
return $templater->render( $html, [
'class-foo',
'bar',
[
[ 'tag' => 'item', 'data' => [ 'The Best Title', $item_1 ] ],
[ 'tag' => 'item', 'data' => [ 'There is no title', $item_2 ] ],
]
] );
$html = <<<TEMPLATE
<div class="popup %1$s" data-popup="%2$s">
%3$s
</div>
[[item]]
<div class="item">
<div class="title">%1$s</div>
<div class="content">
%2$s
</div>
</div>
[[/item]]
[[button]]
<button id="%s">
%s
</button>
[[/button]]
TEMPLATE;
$html = <<<TEMPLATE
<div class="[[classname1|classname2|classname3/]]%d"></div>
TEMPLATE;
$result = $templater->render( $html, [
1,
] );