PHPTAL Extension for Silex
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

PHPTALServiceProvider, a part of Silex Framework Providers

PHPTAL is one of PHP template engines, which is an implementation of the excellent Zope Page Template (ZPT) system for PHP. And Silex is a PHP microframework, which is very light and is based on Symfony2. This extension allow you to use PHPTAL as a template engine in Silex.


the best way to install this service provider is to use composer. as the first, creating composer.json file in your project below:

        "require": {
            "brtriver/PHPTALServiceProvider": "dev-master"

If you also want to install PHPTAL, just added like below:

        "repositories": [
                "type": "package",
                "package": {
                    "name": "pornel/PHPTAL",
                    "version": "1.2.2",
                    "dist": {
                        "url": "",
                        "type": "zip"
                    "source": {
                        "url": "",
                        "type": "git",
                        "reference": "Release 1.2.2"
        "require": {
            "brtriver/PHPTALServiceProvider": "dev-master",
            "pornel/PHPTAL": "1.2.2"

then install composer.php and install

$ wget
$ php composer.phar install

download PHPTALServiceProvider and set to this directory and finally the path of this is below: ./vendor/brtriver/PHPTALServiceProvider/PHPTALServiceProvider.php

Then PHPTAL library is set to ./vendor/phptal directory and PHPTAL templates is set under views directory.

│  ├── .htaccess
│  ├── silex.phar
│  ├── composer.json
│  ├── composer.phar
│  └── index.php
├── vendor
│   ├── bin
│   ├── brtriver
│   │   └── PHPTALServiceProvider
│   │       └─ PHPTALServiceProvider.php
│   └── pornel
│       └── PHPTAL
└── views
    └── teset.html (PHPTAL template files is set here)

Sample Code

in index.php, you require this PHPTALServiceProvider file and register it, then your code is like below:


After calling register method, $app['phptal'] is a instance of PHPTAL. You can use it as PHPTAL itself. You have to set a template path first.

require_once __DIR__.'/silex.phar';
require_once __DIR__.'/vendor/brtriver/PHPTALServiceProvider/PHPTALServiceProvider.php';

use Silex\Provider\PHPTALServiceProvider;

$app = new Silex\Application();
$app['phptal.class_path'] = __DIR__.'/vendor/pornel/PHPTAL';
$app->register(new PHPTALServiceProvider());

$app->get('/hello/{name}', function($name) use($app) {
    // set your view file. view file is set under /views directory
    $app['phptal.view'] = "test.html";
    $app['phptal']->title = "PHPTAL in Silex";
    $app['phptal']->name = $name;
    return $app['phptal']->execute();



<?xml version="1.0"?>
    <title tal:content="title">
      Place for the page title
  </head>  <body>
    <h1 tal:content="title">sample title</h1>
            <td tal:content="name">person's name</td>
          <tr tal:replace="">
            <td>sample name</td>


PHPTALExtension is licensed under the MIT license.