PHP Classes

File: README.md

Recommend this page to a friend!
  Classes of Marco Afonso   Mask   README.md   Download  
File: README.md
Role: Documentation
Content type: text/markdown
Description: Documentation
Class: Mask
Trait to process templates with class functions
Author: By
Last change: Update of README.md
Date: 1 year ago
Size: 1,434 bytes
 

Contents

Class file image Download

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