PHP Template Attribute Language — template engine for XSS-proof well-formed XHTML and HTML5 pages


PHPTAL - Template Attribute Language for PHP

Monthly Downloads License Build Status Scrutinizer Quality Score


If you want to use the builtin internationalisation system (I18N), the php-gettext extension must be installed or compiled into PHP (--with-gettext).

Composer install (recommended)

You can install this package by using Composer. Link to Packagist:

composer require phptal/phptal

Manual install

Get the latest PHPTAL tarball from

tar zxvf PHPTAL-X.X.X.tar.gz
mv PHPTAL-X.X.X/PHPTAL* /path/to/your/php/include/path/


Please see the projects releases page

Getting the latest development version

You can find the latest development version on github:

Addition development requirements (optional)

If you would like to generate the offical html/text handbook by calling make doc, you will need to install the xmlto package. Please use your operating systems package manager to install it.

  • Any plans for dropping PHP < 5.3 support

    Any plans for dropping PHP < 5.3 support

    Hi there

    Just a quick question: Do you have any plans dropping the support for php < 5.3 in future releases? I'm going to write a patch (at least I'll try) which add Namespaces and Interfaces which will break the compatibilty to the current supported versions of php (php 5.1.x?).

    opened by usox 19
  • Ability to use closures in TAL variables

    Ability to use closures in TAL variables

    I think it would be very handy to able pass closures to PHPTAL variables, or to objects that are themselves passed to PHPTAL, such as:

    $tpl->foon = function () { return 'barn'; };

    Currently PHPTAL will try to concatenate $ctx->foon, which results in "Object of Closure could not be converted to string."

    You can get around this via:

    <tal:block content="func:foon"/>
    function phptal_tales_func($src, $nothrow) {
        return 'call_user_func(' . phptal_tales($src, $nothrow) . ')';

    ...but I think this is behavior we can actually build into PHPTAL. I will implement myself if I get positive feedback about this.

    feature request 
    opened by ajcrites 17
  • Release 1.2.3

    Release 1.2.3

    It's been a while. Shall we make a release?

    I wonder if #9 needs to be fixed before next version can be released. Slots in nested macros are a pain. The 1.2.2 version doesn't get it right either, but is buggy in a different way :(

    Other than that it's pretty good:

    • Support for closures
    • default json and urlencode modifiers
    • Support for namespaced classes in TALES modifiers
    • Improved registering and unregistering of custom TALES modifiers
    • Updated list of HTML5 elements/attributes
    • Better error messages when keys are missing in arrays
    • Improvements to HTML-compressing prefilter
    • Consistent checks for truthy values
    • Non-UTF-8 encoding support in PHP 5.4
    • Throwing in chained expressions
    • bunch of other bugfixes
    opened by kornelski 14
  • Stable version number for Composer users

    Stable version number for Composer users

    Currently PHPTAL package is released only as dev-master via Packagist. But it does not have stable code and users may be confused by difference of each other in the same release name 'master'.

    I suggest to point a version number tag as 1.2.3 to master brach. Then Packagist can take it as new numbered release package.

    I and my friends want to use PHPTAL by Composer but also want to use a stable version of it. (It also includes HTML5 tag fix.)

    opened by tanakahisateru 11
  • Adding PHPTAL_lint to bin directoy

    Adding PHPTAL_lint to bin directoy

    Installs the lint tool in the composer bin directory.

    I wasn't sure whether to rename phptal_lint.php to phptal_lint as other tools don't have the .php extension but I thought it was best to leave it for now in case anyone is using any test tools which expect tools/phptal_lint.php to exist

    opened by REBELinBLUE 8
  • tal:omit-tag should have higher priority like condition or above

    tal:omit-tag should have higher priority like condition or above

    If you want to have a tag ommited, using the omit-tag directive, but, for example in this tag you want to access the same attribute you are checking to omit the tag, PHPTAL throws an error.

    An example could be to display an image in a gallery and add a link to that image. Some images have link some others do not. You could wrap the img tag into an a tag, using tal:omit-tag to check if the $image/link exists. If it does, $image/link could be used to set the href attribute using the tal:attributes tag.

    Here the code:

    <a tal:omit-tag="not:exists:item/link" tal:attributes="href item/link">
        <img tal:attributes="src item/image" />

    In its current implementation, this throws an error, because PHPTAL checks tal:attributes before it checks tal:omit-tag.

    improvement can't reproduce/won't fix 
    opened by jah0wl 6
  • Looking for a new maintainer

    Looking for a new maintainer

    I haven't done much PHPTAL work in recent years, and currently I'm focused on completely different projects.

    I still think it's the best templating language for PHP. The code is good and stable.

    Is anybody interested in taking over the project?

    opened by kornelski 6
  • Add support for subpaths in the codedestination

    Add support for subpaths in the codedestination

    When using tal with a high amount of different templates and macros (I'm talking about millions of different templates), the code destination folder gets filled up with cache files within no time - especially if you dont want to clear the directory every 10 minutes. This slows down the filesystem access to the specific directory (depends on the environment - filesystemtype, nfs, etc.).

    This patch introduces a configurable level of subpaths which are added to the phpCodeDestination to create a structure of max 32 subpaths with 0 as default to avoid impacts on existing installations.

    feature request 
    opened by usox 6
  • Question/Composer-dev


    The readme currently makes no mention that PHPTAL can be installed through Composer, also the DEV dependencies mentioned in the README file do not appear in the composer.json file.

    Maybe I could patch the readme and composer files to fix this?

    documentation improvement 
    opened by Potherca 6
  • PHPTAL-14 Question/Composer-dev

    PHPTAL-14 Question/Composer-dev

    • Adds instructions to the README file on how to use PHPTAL with Composer.
    • Adds a 'require-dev' section to the composer.json file so the development requirements can be installed through Composer.
    • Does minor cleanup for the links in the README file.

    closes #14

    opened by Potherca 5
  • `tal:attributes` booleans not set properly, do not validate

    `tal:attributes` booleans not set properly, do not validate

    If you set a boolean attribute on an element using tal:attributes, it will use the value of the variable instead of setting the boolean value. This results in invalid HTML for that attribute.

    The boolean attribute list is also incomplete for HTML5, but that is probably a separate issue.

    To reproduce, use code/template like this:

    $tpl->boolat = true;
    <!DOCTYPE html>
       <head><title>Boolean Not setting</title></head>
          <input tal:attributes="disabled boolat" />

    When the template is emitted, it will specify disabled="1", and this does not validate at least for HTML5. If you set a boolean attribute without using tal:attributes, it will be set properly.

    bug - confirmed 
    opened by ajcrites 5
  • setLanguage throws error with empty strings.

    setLanguage throws error with empty strings.

    This code:

    $TALTranslator = new \PHPTAL_GetTextTranslator();
    $TALTranslator->addDomain('mydomain', './locale');
    $TALTranslator->setLanguage('', 'en_US'); // Empty string as first argument

    Will throw this exception:

    Language(s) code(s) ", en_US" not supported by your system.

    Looks like some sort of strange string concatenation problem as indicated by the leading comma in the list of languages in the error.

    opened by adjenks 3
  • Need atomic write when preparing code

    Need atomic write when preparing code

    in line PHPTAL.php:828 used not atomic writes via file_put_contents if (!file_put_contents($this->getCodePath(), $result)) {

    OpCache in some cases is in time to store an empty file into the cache. Potential reasons for it is high RPS, high concurency, slow disks and so on.

    File exists, it's not empty, there are no errors while requiring file, but function is not defined and we have this log message: E_ERROR: Call to undefined function tpl_... in: /var/local/www/app/outsource/PHPTAL/PHPTAL.php:667

    opened by alantum 5
  • documentation not up to date with latest features

    documentation not up to date with latest features

    I recently used the features described in the NEWS section:

    PHPTAL 1.3.0 2014-03-16

    Added support for closures
    Added support for namespaced classes in TALES modifiers
    Added default json and urlencode modifiers

    In particular the urlencode modifiers.

    I was looking everywhere how to do it, but I couldn't find them in the documentation, only in the NEWS section. I'm glad they are there, and they work, even inside of escaped variables like so:

     <a tal:attributes="href string:${urlencode:myVarWithBadCharacters}">test</a>

    which is awesome, but documentation should really be there.

    opened by adjenks 1
  • Lacking full support for Closures

    Lacking full support for Closures

    On the releases page it states that there was added support for closures:

    However, I found that when I used a closure directly on a template variable a closure would not work. Only when using a "repeat" tag do closures appear to work. I'm not sure where you would fix this, but I found that closure support was provided in RepeatController.php in these lines:

    elseif ($source instanceof Closure) {
        $this->iterator = new ArrayIterator( (array) $source() );

    So perhaps something similar needs to be done.

    For example this will fail to load: $details = function(){return 'some string';}; $template->details = $details;

    <b tal:content="details"></b>

    But if $details was a closure that returned an array and it was iterrated over like so it works:

     $details = function(){return [0=>['name'=>'Jim']];};
    <li tal:repeat="detail details" class="media">
        <div tal:content="detail/name">Name Here</div>

    There might be a typo somewhere in that code but you should get the idea.

    I wanted to use a closure to lazy load my template variable but it only worked when I used repeat, so I believe I found a problem. I found that I can temporarily work around this problem by returning a one element array and using the tal:repeat directive.

    bug - confirmed 
    opened by adjenks 4
  • PHPTAL website hosting

    PHPTAL website hosting


    In the conversation on #48, it became apparent that it might be useful for the PHPTAL website to fall under the same responsibility as the code-base.

    Currently the PHPTAL site is hosted on @pornel's personal server.

    It might be a good idea to set up a repo and use Github Pages to host the content of the PHPTAL website.

    This issue is for discussing the pro's/con's and details of what such a plan entails.


    The website currently consists of the following sections:

    • Download
    • FAQ
    • Introduction / Homepage
    • Mailinglist
    • Manuals
    • News
    • RSS/Atom News Feed
    • Wiki

    As far as I can tell all of the pages can be served from static content except for the wiki. Github offers wiki functionality, so that might be enough to port the current wiki to.

    Github Pages also has support for RSS feeds so that shouldn't cause a problem.

    Having all the docs (both the manual and the site) in a repo would allow people to send in PRs and would make it possible to automate things.

    If PEAR support is eventually dropped, would not longer have to be updated. For the time being, this would constitute a commit/PR for each new release. (If that becomes too cumbersome the process could be automated in a build step).

    opened by Potherca 7
⚡️ Simple and fastly template engine for PHP

EasyTpl ⚡️ Simple and fastly template engine for PHP Features It's simple, lightweight and fastly. No learning costs, syntax like PHP template It is s

PHPPkg 19 Dec 9, 2022
PHP template engine for native PHP templates

FOIL PHP template engine, for PHP templates. Foil brings all the flexibility and power of modern template engines to native PHP templates. Write simpl

Foil PHP 167 Dec 3, 2022
Twig, the flexible, fast, and secure template language for PHP

Twig, the flexible, fast, and secure template language for PHP Twig is a template language for PHP, released under the new BSD license (code and docum

Twig 7.7k Jan 1, 2023
A complete and fully-functional implementation of the Jade template language for PHP

Tale Jade for PHP Finally a fully-functional, complete and clean port of the Jade language to PHP — Abraham Lincoln The Tale Jade Template Engine brin

Talesoft 91 Dec 27, 2022
Smarty is a template engine for PHP, facilitating the separation of presentation (HTML/CSS) from application logic.

Smarty 3 template engine Documentation For documentation see Requirements Smarty can be run with PHP 5.2 to PHP 7.4

Smarty PHP Template Engine 2.1k Jan 1, 2023
View template engine of PHP extracted from Laravel

Blade 【简体中文】 This is a view templating engine which is extracted from Laravel. It's independent without relying on Laravel's Container or any others.

刘小乐 143 Dec 13, 2022
Twig Template Engine to Phalcon PHP

Twig Template Engine to Phalcon PHP

Vinicius 4 Oct 7, 2022
Liquid template engine for PHP

Liquid is a PHP port of the Liquid template engine for Ruby, which was written by Tobias Lutke. Although there are many other templating engines for PHP, including Smarty (from which Liquid was partially inspired)

Harald Hanek 230 Aug 18, 2022
Pug (Jade) template engine for Symfony

Pug-Symfony Pug template engine for Symfony This is the documentation for the ongoing version 3.0. Click here to load the documentation for 2.8 Instal

Pug PHP 41 Dec 16, 2022
PHPlater, a simple template engine.

PHPlater A simple PHP template engine that lets PHP do all the logic and then append it to the HTML in the template file. It is set to solve the probl

John Larsen 2 Jun 3, 2022
Prosebot is a template-based natural language generation application

Prosebot is a template-based natural language generation application. Throughout the last years, ZOS has been developing Prosebot, alongside their collaboration with FEUP, as part of the project.

Zerozero 12 Dec 15, 2022
Contao extension to provide content templates for pages.

Contao Content Templates In Contao, the regular content of a page can be made up of different articles, each assigned to different sections of a page

inspiredminds 7 Oct 11, 2022
A template abstraction prototype for PHP template engines

Schranz Templating A template abstraction prototype for PHP template engines. This project should help to find a way for a general Template Render Int

Schranz Templating 16 Dec 7, 2022
Provides TemplateView and TwoStepView using PHP as the templating language, with support for partials, sections, and helpers.

Aura View This package provides an implementation of the TemplateView and TwoStepView patterns using PHP itself as the templating language. It support

Aura for PHP 83 Jan 3, 2023
Standalone Skeltch templating engine for PHP

SkeltchGo is a standalone version of Glowie Skeltch templating engine for PHP, intented to use from outside the framework.

glowie 1 Nov 5, 2021
Multi target HAML (HAML for PHP, Twig, )

Multi target HAML MtHaml is a PHP implementation of the HAML language which can target multiple languages. Currently supported targets are PHP and Twi

Arnaud Le Blanc 363 Nov 21, 2022
SwitchBlade: Custom Directives for the Laravel Blade templating engine

SwitchBlade: Custom Directives for the Laravel Blade templating engine

Awkward Ideas 10 Nov 29, 2022
Experimental ActiveRecord layer on top of Doctrine2 using the Twig templating engine

This is an experiment for building ActiveRecord functionality on top of Doctrine2 using the Twig templating engine. Whether it is called Propel2 or not is irrelevant.

Francois Zaninotto 85 Dec 5, 2022
A PHP project template with PHP 8.1, Laminas Framework and Doctrine

A PHP project template with PHP 8.1, Laminas Framework and Doctrine

Henrik Thesing 3 Mar 8, 2022