PHP code example of irfantoor / template-engine

1. Go to this page and download the library: Download irfantoor/template-engine 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/ */

    

irfantoor / template-engine example snippets


$te = new IrfanTOOR\TemplateEngine([
    'max_depth' => 3, # defaults to 3
    'base_path'  => 'your/path/to/template/files/',
]);

$text = "{$greeting} {$user}!";
$data = [
    'greeting' => 'Hello',
    'user' => 'World',
];

echo $te->processText($text, $data);

# home.php
<h1>{$title}</h1>

<ul>
{@foreach ($list as $item):}
<li>{$item}</li>
{@endforeach}
</ul>

$data = [
    'title' => 'Fruits',
    'list' => [
        'Apple',
        'Orange',
        'Blackberry',
        'Raspberry',
    ],
];

echo $te->processFile("home.php", $data);

{# its a comment!}
{#anything here including the external brackets are removed from the output}

{@{@echo date('d-m-Y')}

{@if ($list):}
    # Note: you can use the curley brackets, so use the form foreach (...): endforeach instead
    {@foreach ($list as $k => $v):}
    data provided is : {$k} | {$v}
    {@endforeach}
{@endif}



# you can define the data in the template
{@ $d = date('d-m-Y')}

# and prints ...
date : {$d}

# Note: The statement in {@ ...} tags need not to be terminated with a semicolon ';'
{@ $list = [
    'black',
    'white'
]}

dump list:
# Note: The variable to dump, might as well be an object, array, bool int or a string
{$list}