PHPackages                             xorock/zend-expressive-phptalrenderer - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. xorock/zend-expressive-phptalrenderer

ActiveLibrary[HTTP &amp; Networking](/categories/http)

xorock/zend-expressive-phptalrenderer
=====================================

PHPTAL integration for Expressive

0.1.1(9y ago)025BSD-3-ClausePHPPHP ^5.5 || ^7.0

Since Jul 18Pushed 9y ago1 watchersCompare

[ Source](https://github.com/xorock/zend-expressive-phptalrenderer)[ Packagist](https://packagist.org/packages/xorock/zend-expressive-phptalrenderer)[ RSS](/packages/xorock-zend-expressive-phptalrenderer/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (2)Dependencies (6)Versions (4)Used By (0)

PHPTAL Integration for Expressive
=================================

[](#phptal-integration-for-expressive)

Provides [PHPTAL](http://phptal.org/) integration for [Expressive](https://github.com/zendframework/zend-expressive).

Installation
------------

[](#installation)

Install this library using composer:

```
$ composer require xorock/zend-expressive-phptalrenderer
```

We recommend using a dependency injection container, and typehint against [container-interop](https://github.com/container-interop/container-interop). We can recommend the following implementations:

- [zend-servicemanager](https://github.com/zendframework/zend-servicemanager): `composer require zendframework/zend-servicemanager`
- [pimple-interop](https://github.com/moufmouf/pimple-interop): `composer require mouf/pimple-interop`
- [Aura.Di](https://github.com/auraphp/Aura.Di)

Configuration
-------------

[](#configuration)

The following details configuration specific to PHPTAL, as consumed by the `PhptalRendererFactory`:

```
use Zend\ServiceManager\Factory\InvokableFactory;
use Zend\Expressive\Phptal\HelperManager;
use Zend\Expressive\Phptal\Helper;
use Zend\Expressive\Phptal\PhptalEngineFactory;
use PHPTAL as PhptalEngine;

return [
    'dependencies' => [
        'factories' => [
            'Zend\Expressive\FinalHandler' =>
                Zend\Expressive\Container\TemplatedErrorHandlerFactory::class,

            Zend\Expressive\Template\TemplateRendererInterface::class =>
                Zend\Expressive\Phptal\PhptalRendererFactory::class,
            PhptalEngine::class => PhptalEngineFactory::class,

            HelperManager::class => InvokableFactory::class,
            Helper\UrlHelper::class => Helper\UrlHelperFactory::class,
            Helper\ServerUrlHelper::class => Helper\ServerUrlHelperFactory::class,
        ],
    ],

    // if enabled, forces to reparse templates every time
    'debug' => boolean,

    'templates' => [
        'extension' => 'file extension used by templates; defaults to html',
        'paths' => [
            // Paths may be strings or arrays of string paths.
        ],
        'paths' => 'templates' // Defaults to `templates` directory
    ],

    'phptal' => [
        'cache_dir' => 'path to cached templates',
        // if enabled, delete all template cache files before processing
        'cache_purge_mode' => boolean,
        // set how long compiled templates and phptal:cache files are kept; in days
        'cache_lifetime' => 30,
        'encoding' => 'set input and ouput encoding; defaults to UTF-8',
        // one of the predefined constants: PHPTAL::HTML5,  PHPTAL::XML, PHPTAL::XHTML
        'output_mode' => PhptalEngine::HTML5,
        // set whitespace compression mode
        'compress_whitespace' => boolean,
        // strip all html comments
        'strip_comments' => boolean,
        'helpers' => [
            // helper service names or instances
        ]
    ],
];
```

Included helpers and functions
------------------------------

[](#included-helpers-and-functions)

The included `HelperManager` adds support for using own functions inside templates proxying built-in `helper`custom expression modifier to user class. User class has to implement `HelperInterface` and `__invoke()` method.

The following template helpers are automatically activated if UrlHelper and ServerUrlHelper are registered with the container:

- `url`: Shortcut for [UrlHelper](https://github.com/zendframework/zend-expressive/blob/master/doc/book/features/helpers/url-helper.md)

    ```
    Link
    Generates: /article/3
    ```
- `serverurl`: Shortcut for [ServerUrlHelper](https://github.com/zendframework/zend-expressive/blob/master/doc/book/features/helpers/server-url-helper.md)

    ```
    Link
    Generates: /foo
    ```

As an example we can create own helper based on DateTime object:

```
use DateTime;
use Zend\Expressive\Phptal\Helper\HelperInterface;

class DateTimeHelper implements HelperInterface
{
    const HELPER_NAME = 'datetime';

    public function __invoke(DateTime $datetime = null)
    {
        if ($datetime === null) {
            $datetime = new DateTime();
        }
        return $datetime->format(DateTime::ISO8601);
    }

    /**
     * {@inheritdoc}
     */
    public function getHelperName()
    {
        return self::HELPER_NAME;
    }
}
```

Now we need to pass it to configuration array:

```
'dependencies' => [
    'aliases' => [
        'dateTimeHelper' => DateTimeHelper::class,
    ],
    'factories' => [
        DateTimeHelper::class => DateTimeHelperFactory::class,
    ],
],

'phptal' => [
    'helpers' => [
        DateTimeHelper::class, // or 'dateTimeHelper' alias
    ]
]
```

Then pass new DateTime from SomeAction to our template:

```
$date = new \DateTime();
$data['date'] = $date;
$this->template->render('app::home-page', $data)
```

And inside template:

```
${helper:datetime(date)}
Will show current date in ISO 8601 format
```

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~201 days

Total

2

Last Release

3383d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4a242d64bfef45ebfdd057cb2e8f52adb060a22dd0ee23d8925f61d1f3f2f079?d=identicon)[xorock](/maintainers/xorock)

---

Top Contributors

[![xorock](https://avatars.githubusercontent.com/u/111481?v=4)](https://github.com/xorock "xorock (5 commits)")

---

Tags

httppsrpsr-7middlewareexpressivephptal

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/xorock-zend-expressive-phptalrenderer/health.svg)

```
[![Health](https://phpackages.com/badges/xorock-zend-expressive-phptalrenderer/health.svg)](https://phpackages.com/packages/xorock-zend-expressive-phptalrenderer)
```

###  Alternatives

[psr/http-server-middleware

Common interface for HTTP server-side middleware

18091.2M1.5k](/packages/psr-http-server-middleware)[mezzio/mezzio

PSR-15 Middleware Microframework

3883.6M97](/packages/mezzio-mezzio)[mezzio/mezzio-router

Router subcomponent for Mezzio

265.0M61](/packages/mezzio-mezzio-router)[mezzio/mezzio-helpers

Helper/Utility classes for Mezzio

134.3M67](/packages/mezzio-mezzio-helpers)[mezzio/mezzio-fastroute

FastRoute integration for Mezzio

162.7M52](/packages/mezzio-mezzio-fastroute)[mezzio/mezzio-tooling

Migration and development tooling for Mezzio

191.1M21](/packages/mezzio-mezzio-tooling)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
