Mask is a basic PHP template engine
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
demo
src/Taviroquai/Mask
.gitignore
LICENSE
README.md
composer.json
composer.lock
composer.phar

README.md

mask

Mask is a PHP trait that functions as a basic PHP template engine

Tutorial

create a simple view to hold ALL view logic


class MyView
{
    protected $title = 'Hello';
    protected function logic()
    {
        return 'World!';
    }
}

add mask


use Taviroquai\Mask\Mask;

class MyView
{
    use Mask;
    
    protected $title = 'Hello';
    protected function logic()
    {
        return 'World!';
    }
}

now create an HTML file: template.html

<p>
{{ title }}
{{ if logic }}{{ logic }}{{ endif }}
</p>

finally use it in PHP as


$view = new MyView;
echo $view->mask('template');

output:

<p>
Hello
World!
</p>

API

Call variables and methods

{{ variableName }} {{ methodName }}

Conditions

{{ if methodOrVariableName }} ... something ... {{ endif }}

Foreach loops

{{ for variable as local }}
{{ local }}
{{ endfor }}

Includes

include partial.html
{{ include partial }}

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'
        );
    }
}