mask
Mask is a PHP trait that functions as a basic PHP template engine, (*1)
Tutorial
create a simple view to hold ALL view logic, (*2)
class MyView
{
protected $title = 'Hello';
protected function logic()
{
return 'World!';
}
}
add mask, (*3)
use Taviroquai\Mask\Mask;
class MyView
{
use Mask;
protected $title = 'Hello';
protected function logic()
{
return 'World!';
}
}
now create an HTML file: template.html, (*4)
<p>
{{ title }}
{{ if logic }}{{ logic }}{{ endif }}
</p>
finally use it in PHP as, (*5)
$view = new MyView;
echo $view->mask('template');
output:, (*6)
<p>
Hello
World!
</p>
API
Call variables and methods
{{ variableName }}
{{ methodName }}, (*7)
Conditions
{{ if methodOrVariableName }}
... something ...
{{ endif }}, (*8)
Foreach loops
{{ for variable as local }}
{{ local }}
{{ endfor }}, (*9)
Includes
include partial.html
{{ include partial }}, (*10)
Options
// Set cache path
Mask::$templateCachePath = './path/to/cache';
// Set templates path
Mask::$templatePath = './path/to/templates';
// Choose what properties to publish by overriding getMaskData()
class MyView
{
use Mask;
protected $property1;
protected $property2;
public function getMaskData()
{
return array(
'property2' => 'override'
);
}
}