Download the PHP package mkgor/puff without Composer
On this page you can find all versions of the php package mkgor/puff. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package puff
Short Description Flexible and lightweight template engine for PHP
License MIT
Informations about the package puff
Puff
Hackable and lightning fast template engine for PHP, which is inspired by Twig.
Contents
- Requirments
- Installation
- Quickstart
- Specification
- Filters
- Extensions system
- Syntax editing
- Escaping tags
Requirments
- PHP 7.1 or higher (for Puff core)
- Mbstring extension (for UpperCaseFilter)
Installation
Install Puff via composer
`
Quickstart
``
`
Important! Don't forget to initialze CoreModule here if you need all basic statements, such as for, if-else, etc.
Also important! Puff automatically converts '-' and '.' symbols into '_' in variable's name.
Specification
Instructions for executing basic statements, such as if-else, for, import, etc. indicated by combination of characters `
To display variable's value, you should use `
For
Working like PHP's foreach cycle
`
If-else
Simple if-else implementation
`
Import
You can import template into another using import
If you are not specified templates directory path, you should set template path relative to project root
Important! Don't forget, that you are injecting all variables from current template into importing template. If template which you are importing using some variable (for example - it is displaying page title in header), you should specify it in render method `
Set
Creates/Updates variable
`
Extends and Position
Use this tags to define the parent template and load data from the current template into it using the Position tag.
Usage:
Main template `
Parent template `
Filters system
You can modify some variables before displaying them or if some statement supports filters, you can modify variable before using it in it.
To specify filters for variable, you should specify them by ~ sign.
Example:
`
`
You also can use filters in for statement
`
You can create your own filters. Read how to do it in Extensions system block
Extensions system
Puff is extensible, so you can create your own modules, which can contain your own statements and filters.
To create module, just create class which implements Puff\Modules\ModuleInterface and insert in into modules array of Engine configuration
``
Important! Don't forget to initialze CoreModule here if you need all basic statements, such as for, if-else, etc.
Making new statement (element)
To make new element, you should create class, which should extend Puff\Compilation\Element\AbstractElement
You should specify element's class in your Module class's setUp() method:
``
Now, your element is accessible in template by test_element keyword
Element's process method should return PHP code.
``
You can provide some attributes handling rules. By default, it is handling like this: `
But if you want to make statement like for (which don't use attributes like "attribute='attr'") you can provide your own attributes handling rules by specifying handleAttributes method in your element class
It is getting an array of all elements from tokenizer and should return an array
For example:
`
``
`
Making new filter
To make new element, you should create class, which should extend Puff\Compilation\Element\AbstractElement
You should specify element's class name in Module's class setUp() method:
``
Your filter class should implement Puff\Compilation\Filter\FilterInterface
For example, discover UpperCaseFilter code to understand how it works
``
Value, which handle method returns, will be assigned to variable
Syntax editing
You can configure some elements of syntax, such as symbols which are Puff using in tags, equality symbol, filter separator symbol and etc.
To do this, you should create new class, which can implements Puff\Tokenization\Syntax\SyntaxInterface or extends Puff\Tokenization\Syntax\AbstractSyntax. Let's see how it works with AbstractSyntax
``
So, we are specified new element tag's symbols. To make it work, you should set it in the configuration array in Engine constructor, or set it in Module's setUp() method.
``
Now, all tags should use new syntax, let's see how we should update template
`
Escaping tags
To escape tag, you should set escaping symbols before some tag to tell compiler to ignore it.
Default escaping symbols in Puff is //
, but you can edit it by setting your own Syntax class
`
Will display: `
All versions of puff with dependencies
ext-mbstring Version *