Newsletter
Join the Community
Subscribe to our newsletter for the latest news and updates
Simple and fast template engine for PHP that compiles templates to native PHP syntax.
EasyTpl is a lightweight PHP template engine that compiles template files into native PHP syntax for fast rendering. It provides a simple, PHP-like syntax with {{ ... }} delimiters, automatic HTML escaping, and a small footprint for embedding in any PHP application.
EasyTpl is an open-source template engine developed and maintained by the phppkg organization on GitHub. It accepts template strings or template files written in a mix of HTML, plain text, and {{ ... }} directives, combines them with a PHP data array, and outputs rendered text. Because templates are converted into native PHP code, the engine requires PHP to run and is installed with Composer via phppkg/easytpl. The package ships with two classes: EasyTemplate for HTML view templates with output filtering enabled, and TextTemplate for plain-text output with filtering turned off.
if, elseif, else, foreach, for, and switch, so there is no new template language to learn.{{ name }}, {{ $name }}, {{= $name }}, or {{ echo $name }}; the $ prefix is optional and the compiler appends it automatically.{{ $map.user.name }} or {{ $arr.0 }}, without writing PHP array access code.htmlspecialchars by default for safety; escaping can be disabled globally with disableEchoFilter() or per-variable with the raw filter.{{ $var | ucfirst }} works immediately; built-in filters include upper, lower, and nl, and new ones can be registered with addFilter().addDirective(). The built-in directives are layout, include, and contents.ExtendTemplate class introduces extends, block, and endblock directives, letting child templates override specific blocks of a parent layout.{{# ... #}} is ignored during rendering, including multi-line comment blocks.TextTemplate class disables HTML escaping so generated text is not altered.renderString() or display() to receive escaped, secure HTML output.ExtendTemplate with extends and block directives to define a master layout and override content sections in child templates.{{ include('part/header.tpl', ['title' => 'My world']) }}.TextTemplate to render unescaped text for code generation, config files, or reports.When you call renderString() or display(), EasyTpl parses the template's {{ ... }} expressions and control blocks, compiles them into native PHP code, then executes that code with the supplied variable array. The result is returned as a string or written directly to the output buffer, making it straightforward to drop into an existing PHP page or router.
EasyTpl's README lists several related PHP template engines as alternatives: Twig, Latte, Blade, Fenom, and Pug. Each has its own syntax and feature set; EasyTpl positions itself as simpler and faster, compiling directly to PHP.
Yes, EasyTpl is open source and distributed under the MIT License. Its source code is hosted on GitHub under the phppkg organization.
Install EasyTpl with Composer by running composer require phppkg/easytpl. The package's PHP version requirement and latest release are shown on the repository's badge.
Yes, by default EasyTemplate runs every echoed variable through htmlspecialchars. You can disable this globally with $t->disableEchoFilter() or per-variable with the raw filter, as in {{ $name | raw }}.
Yes. Use $tpl->addFilter('name', callable) to register one filter or $tpl->addFilters([...]) to register several at once. Custom filters are used the same way as built-in filters, for example {{ $name | last3chars }}.
EasyTemplate keeps output filtering on and is meant for rendering HTML view templates. TextTemplate disables output filtering and is designed for text processing, code generation, and other non-HTML output where escaping would be unwanted.