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.

  • I get malware warnings on the file SasXmlParser.php

    I get malware warnings on the file SasXmlParser.php

    Malware found: {HEX}php.base64.v23au.185

    I think it is a false positive, but I cannot find out what is causing the issue in this file.

    opened by lengthofrope 25
  • 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
  • Adding first composer setup definition

    Adding first composer setup definition

    opened by Ocramius 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
  • Added ja Manual

    Added ja Manual

    Renewed manual on Japanese, in docBook form.

    opened by shivashanti 8
  • 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
  • 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
  • Upgrade to GitHub-native Dependabot

    Upgrade to GitHub-native Dependabot

    Dependabot Preview will be shut down on August 3rd, 2021. In order to keep getting Dependabot updates, please merge this PR and migrate to GitHub-native Dependabot before then.

    Dependabot has been fully integrated into GitHub, so you no longer have to install and manage a separate app. This pull request migrates your configuration from to a config file, using the new syntax. When merged, we'll swap out dependabot-preview (me) for a new dependabot app, and you'll be all set!

    With this change, you'll now use the Dependabot page in GitHub, rather than the Dependabot dashboard, to monitor your version updates, and you'll configure Dependabot through the new config file rather than a UI.

    If you've got any questions or feedback for us, please let us know by creating an issue in the dependabot/dependabot-core repository.

    Learn more about migrating to GitHub-native Dependabot

    Please note that regular @dependabot commands do not work on this pull request.

    opened by dependabot-preview[bot] 2
  • SVG xlink:href throws an error

    SVG xlink:href throws an error

    opened by mkkeck 2
  • 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
  • PHP requirement in the readme is outdated

    PHP requirement in the readme is outdated

    opened by stof 0
  • 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


    As mentioned elsewhere in the issues, we should (eventually) add a CHANGELOG file to this repository.

    In anticipation of this, I have taken the liberty of setting up release notes for v1.2, v1.3 and v2.0-alpha.

    At a later point (once they have been checked for correctness) those notes can be used as input for the changelog file.

    documentation releases 
    opened by Potherca 0
  • Improve the development/contribution/build/release process

    Improve the development/contribution/build/release process

    Currently there is only a very short note on contribution ("don't forget to send me patches") in the documentation. The current build/release process needs to be documented (and possibly improved).

    Suggested Improvements

    • [ ] Use a CHANGELOG file to tag releases - #52
      Once a changelog is created as part of the process, it should be used to tag releases git tag -F <some-release-notes>
    • [X] Use a newer PHPUnit version (v4 instead of v3) -- #43
    • [ ] Anything else?
    opened by Potherca 0
⚡️ 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 9 Nov 26, 2021
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 163 Nov 20, 2021
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.3k Nov 24, 2021
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 93 May 4, 2021
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 1.9k Nov 23, 2021
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.

刘小乐 145 Aug 13, 2021
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 3 Aug 29, 2021
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 81 Nov 16, 2021
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 362 Aug 5, 2021
SwitchBlade: Custom Directives for the Laravel Blade templating engine

SwitchBlade: Custom Directives for the Laravel Blade templating engine

Awkward Ideas 9 Sep 2, 2021
The free-to-use template for your Imagehost-website made with PHP, HTML and CSS!

The free-to-use template for your Imagehost-website made with PHP, HTML and CSS! Some information before we start This repo is only code related, to a

Ilian 5 Nov 3, 2021
The free-to-use template for your Imagehost-website made with PHP, HTML and CSS!

The free-to-use template for your Imagehost-website made with PHP, HTML and CSS! Some information before we start This repo is only code related, to a

Ilian 5 Nov 3, 2021
A SilverStripe Module with template methods to quickly make use of FocusPoint, LazySizes, and Object-fit

LazyFocusFit A SilverStripe module with template methods to quickly make use of FocusPoint, LazySizes and object-fit. Requirements PHP FocusPoint JS/C

Evans Hunt 8 Oct 12, 2021
Native PHP template system

Plates Plates is a native PHP template system that's fast, easy to use and easy to extend. It's inspired by the excellent Twig template engine and str

The League of Extraordinary Packages 1.3k Nov 19, 2021
A ready-to-use Model View Controller template in PHP

PHP-MVC-Template A ready-to-use Model View Controller template in PHP Use this repo as a template! (Or clone it) Start to configure your MVC file Afte

Loule | Louis 6 Nov 19, 2021
Provides a GitHub repository template for a PHP package, using GitHub actions.

php-package-template Installation ?? This is a great place for showing how to install the package, see below: Run $ composer require ergebnis/php-pack

null 260 Nov 24, 2021
A lightweight template parser used by PyroCMS.

Lex Lex is a lightweight template parser. Lex is released under the MIT License and is Copyrighted 2011 - 2014 PyroCMS Team. Change Log 2.3.2 Convert

PyroCMS 103 Nov 15, 2021
Laravel package template

REPLACE Simple and flexible package template. Usage Replace all occurances of REPLACE (case sensitive) with the name of the package namespace. E.g. th

ARCHTECH 47 Nov 24, 2021