PHPackages                             lorenzoferrarajr/lfj-zfrenderer - 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. [Templating &amp; Views](/categories/templating)
4. /
5. lorenzoferrarajr/lfj-zfrenderer

ActiveLibrary[Templating &amp; Views](/categories/templating)

lorenzoferrarajr/lfj-zfrenderer
===============================

A utility to render PHP view scripts using the Zend Framework 2 PhpRenderer

2131PHP

Since Jun 12Pushed 9y ago1 watchersCompare

[ Source](https://github.com/lorenzoferrarajr/lfj-zfrenderer)[ Packagist](https://packagist.org/packages/lorenzoferrarajr/lfj-zfrenderer)[ RSS](/packages/lorenzoferrarajr-lfj-zfrenderer/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (2)Used By (0)

lfj-zfrenderer
==============

[](#lfj-zfrenderer)

A library to render PHP view scripts using the Zend Framework 2 PhpRenderer

[![Build Status](https://camo.githubusercontent.com/343e5d8ab4e51d00e3098b728b3c1b022d3d1eb2cd17636eec9501cba991c2db/68747470733a2f2f7472617669732d63692e6f72672f6c6f72656e7a6f666572726172616a722f6c666a2d7a6672656e64657265722e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/lorenzoferrarajr/lfj-zfrenderer)

**Warning**: This library is in development. Please specify commit hash if you want to experiment with it.

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

[](#installation)

The suggested installation method is via [composer](https://getcomposer.org/):

```
composer require lorenzoferrarajr/lfj-zfrenderer
```

Immutability
------------

[](#immutability)

An object instantiated from the `Lfj\ZfRenderer\Renderer` class is immutable.

For example, the following code is used to add a custom `HelperPluginManager` instance to the `$renderer` object

```
$helperPluginManager = new \Zend\View\HelperPluginManager();
$helperPluginManager->setService('name', new PrintName());

$renderer = new \Lfj\ZfRenderer\Renderer();
$rendererNew = $renderer->withHelperPluginManager($helperPluginManager);
```

Calling `$renderer->withHelperPluginManager($helperPluginManager);` does not affect the `$renderer` object. Instead a cloned object of `$renderer` containing the specified `$helperPluginManager` is returned.

Usage
-----

[](#usage)

The terms *template* and *view script* are used interchangeably.

Templates are PHP scripts that mix HTML and PHP.

### Rendering a simple template

[](#rendering-a-simple-template)

This is the `view/hello-world.phtml` view script. No PHP is present

```

Hello, World!
```

To render the template, the path to the view script file must be passed as first parameter of the `render` method

```
$template = realpath('view/hello-world.phtml');

$renderer = new \Lfj\ZfRenderer\Renderer();

/** @var \Zend\View\View $view */
$view = $renderer->render($template);

echo $view->getResponse()->getContent();
```

The `render` method returns an instance of `\Zend\View\View`. The content can be retrieved with `$view->getResponse()->getContent()`.

### Passing data to the template

[](#passing-data-to-the-template)

A template can make use of data contained in variables. This is an example

```

Hello, !
```

To pass data to the view script, an associative array must be provided as the second argument of the `render` method

```
$template = realpath('view/hello-name.phtml');

$renderer = new \Lfj\ZfRenderer\Renderer();
$view = $renderer->render($template, array('name' => 'World'));

echo $view->getResponse()->getContent();
```

### Including partials

[](#including-partials)

It could be useful to include other view scripts from within another view script. This can be done passing a list of template path resolvers to the `withResolvers` method. The method returns a new instance of `$renderer`.

This is the `view/hello-partial.phtml` view script which includes a partial

```
Hello, !
```

and this is the `partial/name.phtml` file

```

```

The code to render the whole thing is this

```
$template = realpath('view/hello-partial.phtml');

$templatePathStack = new \Zend\View\Resolver\TemplatePathStack();
$templatePathStack->addPath(realpath('view'));

$renderer = new \Lfj\ZfRenderer\Renderer();
$renderer = $renderer->withResolvers(array($templatePathStack));

$renderedContent = $renderer->render(
    $template,
    array('name' => 'World')
);

echo $renderedContent->getResponse()->getContent();
```

The `$templatePathStack` object is a list of directories in which other view scripts can be found.

### Adding helpers

[](#adding-helpers)

Helpers can be added injecting an instance of `Zend\View\HelperPluginManager` using the `setHelperPluginManager` method.

The following view script uses the `name` helper.

```
Hello, !
```

An instance of the following `PrintName` class will be used the in the view script when `$this->name()` is called

```
use Zend\View\Helper\AbstractHelper;
use Zend\View\Helper\HelperInterface;

class PrintName extends AbstractHelper implements HelperInterface
{
    public function __invoke()
    {
        echo "World";
    }
}
```

The code that puts all this together is the following

```
$template = realpath('view/hello-helper.phtml');

$helperPluginManager = new \Zend\View\HelperPluginManager();
$helperPluginManager->setService('name', new PrintName());

$renderer = new \Lfj\ZfRenderer\Renderer();
$renderer = $renderer->withHelperPluginManager($helperPluginManager);
$renderedContent = $renderer->render(
    $template
);

echo $renderedContent->getResponse()->getContent();
```

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity43

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/70f7c438f3654500019a262525baa737df7459d7436b51e1ff044999a1c19b1b?d=identicon)[lorenzoferrarajr](/maintainers/lorenzoferrarajr)

---

Top Contributors

[![lorenzoferrarajr](https://avatars.githubusercontent.com/u/1518144?v=4)](https://github.com/lorenzoferrarajr "lorenzoferrarajr (27 commits)")

### Embed Badge

![Health badge](/badges/lorenzoferrarajr-lfj-zfrenderer/health.svg)

```
[![Health](https://phpackages.com/badges/lorenzoferrarajr-lfj-zfrenderer/health.svg)](https://phpackages.com/packages/lorenzoferrarajr-lfj-zfrenderer)
```

###  Alternatives

[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[whitecube/nova-flexible-content

Flexible Content &amp; Repeater Fields for Laravel Nova.

8053.0M25](/packages/whitecube-nova-flexible-content)[mopa/bootstrap-bundle

Easy integration of twitters bootstrap into symfony2

7042.9M33](/packages/mopa-bootstrap-bundle)[limenius/react-bundle

Client and Server-side react rendering in a Symfony Bundle

3871.2M](/packages/limenius-react-bundle)[nicmart/string-template

StringTemplate is a very simple string template engine for php. I've written it to have a thing like sprintf, but with named and nested substutions.

2101.7M30](/packages/nicmart-string-template)[symfony/ux-icons

Renders local and remote SVG icons in your Twig templates.

555.8M69](/packages/symfony-ux-icons)

PHPackages © 2026

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