2017 © Pedro Pelรกez
 

library PHPTALServiceProvider

PHPTAL for Silex

image

brtriver/PHPTALServiceProvider

PHPTAL for Silex

  • Saturday, May 18, 2013
  • by brtriver
  • Repository
  • 1 Watchers
  • 6 Stars
  • 36 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 1 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

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][3]. This extension allow you to use PHPTAL as a template engine in Silex., (*1)

Instllation

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

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

If you also want to install PHPTAL, just added like below:, (*3)

    {
        "repositories": [
            {
                "type": "package",
                "package": {
                    "name": "pornel/PHPTAL",
                    "version": "1.2.2",
                    "dist": {
                        "url": "http://phptal.org/files/PHPTAL-1.2.2.zip",
                        "type": "zip"
                    },
                    "source": {
                        "url": "https://github.com/pornel/PHPTAL.git",
                        "type": "git",
                        "reference": "Release 1.2.2"
                    }
                }
            }
        ],
        "require": {
            "brtriver/PHPTALServiceProvider": "dev-master",
            "pornel/PHPTAL": "1.2.2"
        }
    }

then install composer.php and install, (*4)

$ wget http://getcomposer.org/composer.phar
$ php composer.phar install

download PHPTALServiceProvider and set to this directory and finally the path of this is below: ./vendor/brtriver/PHPTALServiceProvider/PHPTALServiceProvider.php, (*5)

Then PHPTAL library is set to ./vendor/phptal directory and PHPTAL templates is set under views directory., (*6)

/project_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:, (*7)

index.php

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., (*8)

<?php
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();
});

$app->run();

test.html

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

License

PHPTALExtension is licensed under the MIT license., (*9)

The Versions

18/05 2013

dev-master

9999999-dev http://github.com/brtriver/PHPTalServiceProvider

PHPTAL for Silex

  Sources   Download

MIT

The Requires

  • php >=5.3.2

 

template silex