2017 © Pedro Peláez
 

library mask

A PHP trait as a basic template engine

image

taviroquai/mask

A PHP trait as a basic template engine

  • Friday, March 20, 2015
  • by taviroquai
  • Repository
  • 1 Watchers
  • 1 Stars
  • 3 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

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

The Versions

20/03 2015

dev-master

9999999-dev

A PHP trait as a basic template engine

  Sources   Download

MIT

The Requires

  • php >=5.3.4

 

by Marco Afonso

20/03 2015

dev-1.0-dev

dev-1.0-dev

A PHP trait as a basic template engine

  Sources   Download

MIT

The Requires

  • php >=5.3.4

 

by Marco Afonso

19/03 2015

v1.0.0

1.0.0.0

A PHP trait as a basic template engine

  Sources   Download

MIT

The Requires

  • php >=5.3.4

 

by Marco Afonso