Download the PHP package phppkg/easytpl without Composer
On this page you can find all versions of the php package phppkg/easytpl. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download phppkg/easytpl
More information about phppkg/easytpl
Files in phppkg/easytpl
Package easytpl
Short Description ⚡️ Simple and fastly template engine for PHP
License MIT
Homepage https://github.com/phppkg/easytpl
Informations about the package easytpl
EasyTpl
⚡️ Simple and fastly template engine for PHP.
Features
- It's simple, lightweight and fastly.
- No learning costs, syntax like PHP template
- It is simply processed and converted into native PHP syntax
- Compatible with PHP native syntax
- support simple echo print syntax. eg:
{{ var }}
{{= $var }}
{{ $var }}
{{ echo $var }}
- allow ignore prefix
$
, will auto append on compile.
- allow ignore prefix
- support chained access array value. eg:
{{ $arr.0 }}
{{ $map.name }}
{{ $map.user.name }}
- support all control syntax. such as
if,elseif,else;foreach;for;switch
- support php builtin function as filters. eg:
{{ $var | ucfirst }}
{{ date('Y-m-d') }}
- More secure, the output will be processed automatically through
htmlspecialchars
by default- You can set to disable output filtering or manually use the
raw
filter
- You can set to disable output filtering or manually use the
- support add custom filters.
- default builtin filters:
upper
lower
nl
- default builtin filters:
- support add custom directive.
EasyTemplate
built in supportlayout
include
contents
ExtendTemplate
built in supportextends
block
endblock
- support comments in templates. eg:
{{# comments ... #}}
Install
composer
Quick start
Output:
More usage
The syntax is the same as the PHP native template, and the special syntax added is just to make it more convenient to use.
EasyTemplate
enables output filtering by default, which can be used to render view templates.TextTemplate
turns off output filtering and is mainly used for text processing, code generation, etc.
Config template
more settings:
Echo variable
The following statements are the same, can be used to print out variable values
More:
By default, the output result will be automatically processed through
htmlspecialchars
, unless disabled or manually usedraw
filter
- Set to disable output filtering
$t->disableEchoFilter()
- Disable output filtering in the template
{{ $name | raw }}
Chained access array
Can use .
to quick access array value.
Use in template:
If blocks
only if
:
if else
:
if...elseif...else
:
For/Foreach blocks
foreach
:
with keys:
Add comments
The contents wrapped with {{
and }}
will be ignored as comments.
multi lines:
Use Filters
Default built-in filters:
upper
- equalsstrtoupper
lower
- equalsstrtolower
nl
- append newline\n
Using the filters
You can use the filters in any of your templates.
Regular usage:
Chained usage:
Passing non-static values:
Passing variables as filter parameters:
Custom filters
Use in template:
Custom directives
You can use the directives implement some special logic.
EasyTemplate
built in support:layout
include
contents
Use layout
- page template
home01.tpl
Use include
Use in template
Extends template
New directives:
extends
extends a layout template file.- syntax:
{{ extends('layouts/main.tpl') }}
- syntax:
block
define a new template block start.- syntax:
{{ block 'header' }}
- syntax:
endblock
mark a block end.- syntax:
{{ endblock }}
- syntax:
Examples for extend
-
on layout file:
layouts/main.tpl
- on page file:
home/index.tpl
Rendered results
Dep packages
Related
- https://github.com/twigphp/Twig
- https://github.com/nette/latte
- https://github.com/jenssegers/blade
- https://github.com/fenom-template/fenom
- https://github.com/pug-php/pug
License
MIT
All versions of easytpl with dependencies
ext-mbstring Version *
toolkit/fsutil Version ~2.0
toolkit/stdlib Version ~2.0