1. Go to this page and download the library: Download airtemplate/airtemplate 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/ */
airtemplate / airtemplate example snippets
re 'path/to/src/Parser.php';
.php';
// replace 'ArrayLoader' by 'FilesystemLoader' or 'CacheLoader' as appropriate
re 'path/to/src/Builder.php';
class Chris {
public $name = "Chris";
public $value = 10000;
public function taxed_value() {
return $this->value - ($this->value * 0.4);
}
public $in_ca = true;
}
use AirTemplate\Builder;
use AirTemplate\Loader\ArrayLoader;
$templates = [
'canonical' => 'Hello {{name}}
You have just won {{value}} dollars!
',
'in_ca' => 'Well, {{taxed_value|data:taxed_value}} dollars, after taxes.
'
];
$chris = new Chris;
$builder = new Builder(new ArrayLoader);
$engine = $builder->build($templates);
echo $engine->render('canonical', $chris);
if ($chris->in_ca == true) {
echo $engine->render('in_ca', $chris);
}
use AirTemplate\Builder;
use AirTemplate\Loader\ArrayLoader;
$templates = [
'canonical' => 'Hello {{name}}
You have just won {{value}} dollars!
{{in_ca|user:inCa}}',
'in_ca' => 'Well, {{taxed_value|data:taxed_value}} dollars, after taxes.
'
];
function inCa($value, $field, $data)
{
global $engine;
if ($value == false) {
return '';
}
return $engine->render('in_ca', $data);
}
$chris = new Chris;
$builder = new Builder(new ArrayLoader);
$engine = $builder->build($templates);
echo $engine->render('canonical', $chris);
class AppView
{
public function showColors($value, $field, $data)
{
if (empty($value)) {
return $this->view->render('no-colors', $data);
}
return $this->view->render('color-table', $value);
}
}
$view = new AppView;
// The view object can be passed to the builder via constructor
$builder = new Builder(new ArrayLoader, $view);
// or it can be later set using the setApp method
$builder->setApp($view);
function getArticleCode($value, $field, &$data)
{
// create a new new field
$data['new_field'] = ...
// return article-code
return $data['type'] . '-' . $data['category1'];
}
// field definition: {{somefield|data:doubleSomething}}
class DataObj
{
public function doubleSomething()
{
return $something * 2;
}
}
// Format the price field with 'sprintf'
// The price field is injected as second parameter, replacing the question mark (?)
{{price|sprintf("$%1.2f", ?)}}
// Convert value to a float and format it using the PHP function 'number_format'
{{value|float|number_format(?, 2, ".", " ")}}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.