PHPackages                             smartive/handlebars-bundle - 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. smartive/handlebars-bundle

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

smartive/handlebars-bundle
==========================

This bundle integrates rendering of Handlebars templates into Symfony2

1.3.1(9y ago)624.3k2[1 issues](https://github.com/smartive/SmartiveHandlebarsBundle/issues)[1 PRs](https://github.com/smartive/SmartiveHandlebarsBundle/pulls)MITPHPPHP &gt;=5.4.0

Since Apr 9Pushed 3y ago11 watchersCompare

[ Source](https://github.com/smartive/SmartiveHandlebarsBundle)[ Packagist](https://packagist.org/packages/smartive/handlebars-bundle)[ RSS](/packages/smartive-handlebars-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (8)Dependencies (9)Versions (9)Used By (0)

[![Build Status](https://camo.githubusercontent.com/47e88e59f7a76f139f33c3753956ee5e5364afd5b9cdd92056c624d93f88a9ea/68747470733a2f2f7472617669732d63692e6f72672f736d6172746976652f536d61727469766548616e646c656261727342756e646c652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/smartive/SmartiveHandlebarsBundle)[![Coverage Status](https://camo.githubusercontent.com/fb74a2bd6254d06edbc0573e3e9ee3ed6d5b99d7c784b6a8b0332ff5d169816b/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f736d6172746976652f536d61727469766548616e646c656261727342756e646c652f62616467652e7376673f6272616e63683d6d617374657226736572766963653d676974687562)](https://coveralls.io/github/smartive/SmartiveHandlebarsBundle?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/009b8d3d4e24e2112740a52017c1eb32ff10eb10df44c851d0f6cb1d0b20bdae/68747470733a2f2f706f7365722e707567782e6f72672f736d6172746976652f68616e646c65626172732d62756e646c652f762f737461626c65)](https://packagist.org/packages/smartive/handlebars-bundle)[![Total Downloads](https://camo.githubusercontent.com/4eafd094dc283d8fd281574a6ddaaf05aac48fa13e795edcdc4ea85bd44671b0/68747470733a2f2f706f7365722e707567782e6f72672f736d6172746976652f68616e646c65626172732d62756e646c652f646f776e6c6f616473)](https://packagist.org/packages/smartive/handlebars-bundle)[![License](https://camo.githubusercontent.com/8acd6074eea951c38b02340c41905e44ef2fa70a31ec7097588fb709b59a39c7/68747470733a2f2f706f7365722e707567782e6f72672f736d6172746976652f68616e646c65626172732d62756e646c652f6c6963656e7365)](https://packagist.org/packages/smartive/handlebars-bundle)

SmartiveHandlebarsBundle
========================

[](#smartivehandlebarsbundle)

Bundle to integrate Handlebars templates into your Symfony2 / Symfony3 application.

This bundle renders handlebars with the help of [xamin/handlebars.php](https://github.com/XaminProject/handlebars.php).

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

[](#installation)

Require the `smartive/handlebars-bundle` package in your composer.json and update your dependencies.

```
{
    …
    "require": {
        "smartive/handlebars-bundle": "dev-master"
    }
    …
}

```

Register the bundle in `app/AppKernel.php`:

```
// app/AppKernel.php
public function registerBundles()
{
    return array(
        // ...
        new Smartive\HandlebarsBundle\SmartiveHandlebarsBundle(),
    );
}
```

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

[](#configuration)

Some of the features can be configured in the `smartive_handlebars` section of `app/config/config.yml`.

### Handlebars file extension

[](#handlebars-file-extension)

The default file extension for Handlebars files is set to `.hbs`. This can be overridden using the following setting (example file extension set to `.handlebars`):

```
smartive_handlebars:
    templating:
        file_extension: .handlebars

```

### Template directories

[](#template-directories)

The `template_directories` setting lets you define where to look for Handlebars templates. You can use Symfony resource notation as well as absolute file paths to configure directories.

```
smartive_handlebars:
    templating:
        template_directories:
            - '@AcmeDemo/Resources/views/Templates'
            - /var/www/templates

```

By default, templates are getting search for in template directories recursively. You can disable this behaviour as follows:

```
smartive_handlebars:
    templating:
        template_directories_recursive: false

```

### Twig extension

[](#twig-extension)

The Handlebars Twig extension is enabled by default. To disable it add this to your configuration:

```
smartive_handlebars:
    twig:
        enabled: false

```

Usage
-----

[](#usage)

### Rendering service

[](#rendering-service)

The `smartive_handlebars.templating.renderer` service offers a `render($templateName, $data)` method which can be use to render Handlebars templates.

### Twig

[](#twig)

To render Handlebars templates in Twig you can use the Twig function `handlebars(templateName, data)`.

Custom Handlebars helpers
-------------------------

[](#custom-handlebars-helpers)

You can add you own Handlebars helpers as tagged services by implementing the `Handlebars\Helper` interface. To find out more about how to write custom helpers please have a look at the [built-in helpers by xamin/handlebars.php](https://github.com/XaminProject/handlebars.php/tree/master/src/Handlebars/Helper).

Once you've implemented your own helper you have to register it as a service using the `smartive_handlebars.helper` tag and an appropriate alias:

```
# app/config/services.yml
services:
    demo_bundle.my_demo_helper:
        class: DemoBundle\Helpers\MyDemoHelper
        tags:
            - { name: smartive_handlebars.helper, alias: myDemo }

```

You now can use your custom Handlebars helper inside your templates as follows:

```
{{#myDemo parameter}}
    {{!-- do stuff --}}
{{/myDemo}}
```

Caching
-------

[](#caching)

The rendering service offers the ability to cache the parsed template between requests for faster rendering.

You can enable caching by setting `smartive_handlebars.cache` to a existing cache service ID in your `app/config/config.yml`:

```
smartive_handlebars:
    cache:
        enabled: true
        service:

```

There are several caching services / strategies available per default:

### Disk

[](#disk)

Service ID: `smartive_handlebars.cache.disk`

Uses [Handlebars\\Cache\\Disk](https://github.com/XaminProject/handlebars.php/blob/master/src/Handlebars/Cache/Disk.php) to read/write file cache in Symfony's cache directory

### APC

[](#apc)

Service ID: `smartive_handlebars.cache.apc`

Uses [Handlebars\\Cache\\APC](https://github.com/XaminProject/handlebars.php/blob/master/src/Handlebars/Cache/APC.php) to read/write cache objects using [APC](http://php.net/manual/en/book.apc.php)

### Redis

[](#redis)

Service ID: `smartive_handlebars.cache.redis`

Uses [PhpRedis](https://github.com/phpredis/phpredis) or [Predis](https://github.com/nrk/predis) to read/write cache objects using a [Redis Server](http://redis.io/). This bundle integrates with [RedisBundle](https://github.com/snc/SncRedisBundle) in order to make configuring your Redis implementation even easier. The default Redis client being used is `snc_redis.default` (see [RedisBundle documentation](https://github.com/snc/SncRedisBundle/blob/master/Resources/doc/index.md#usage)).

The default configuration can be overridden looks as follows:

```
smartive_handlebars:
    cache:
        redis:
            client_service: snc_redis.default
            key_prefix: 'smartive-handlebars:'

```

### Custom

[](#custom)

You can also define your own caching services by adding a class which implements [Handlebars\\Cache](https://github.com/XaminProject/handlebars.php/blob/master/src/Handlebars/Cache.php). To use your custom cache service you have to register it in your service configuration:

```
# app/config/services.yml
services:
    demo_bundle.my_demo_cache_service:
        class: DemoBundle\Cache\CustomCache

```

```
# app/config/config.yml
smartive_handlebars:
    cache: demo_bundle.my_demo_cache_service

```

Complete configuration example
------------------------------

[](#complete-configuration-example)

```
# app/config/config.yml
smartive_handlebars:
    templating:
        enabled: true
        file_extension: .hbs
        template_directories:
            - '@AcmeDemo/Resources/views/Templates'
            - /var/www/templates
        template_directories_recursive: true
    twig:
        enabled: true
    cache:
        enabled: false
        service: smartive_handlebars.cache.redis
        redis:
            client_service: snc_redis.default
            key_prefix: 'smartive-handlebars:'

```

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance17

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 75% 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 ~91 days

Recently: every ~99 days

Total

8

Last Release

3416d ago

Major Versions

0.2.0 → 1.0.02015-08-26

PHP version history (2 changes)0.1.0PHP &gt;=5.5.0

1.0.0PHP &gt;=5.4.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/758aab6186392f4cef94a3bd90e8f0d11ef16181dc07e452a1d24224e4b53d48?d=identicon)[mfeltscher](/maintainers/mfeltscher)

---

Top Contributors

[![mfeltscher](https://avatars.githubusercontent.com/u/1352744?v=4)](https://github.com/mfeltscher "mfeltscher (51 commits)")[![thilohaas](https://avatars.githubusercontent.com/u/758837?v=4)](https://github.com/thilohaas "thilohaas (7 commits)")[![petermanser](https://avatars.githubusercontent.com/u/292951?v=4)](https://github.com/petermanser "petermanser (6 commits)")[![dbu](https://avatars.githubusercontent.com/u/76576?v=4)](https://github.com/dbu "dbu (3 commits)")[![rndstr](https://avatars.githubusercontent.com/u/32963?v=4)](https://github.com/rndstr "rndstr (1 commits)")

---

Tags

handlebarshandlebars-templatephpsymfonysymfony2symfony3twigtwigtemplatinghandlebars

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/smartive-handlebars-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/smartive-handlebars-bundle/health.svg)](https://phpackages.com/packages/smartive-handlebars-bundle)
```

###  Alternatives

[timber/timber

Create WordPress themes with beautiful OOP code and the Twig Template Engine

5.7k3.4M111](/packages/timber-timber)[twig/extra-bundle

A Symfony bundle for extra Twig extensions

91292.0M315](/packages/twig-extra-bundle)[symfony/ux-icons

Renders local and remote SVG icons in your Twig templates.

545.8M69](/packages/symfony-ux-icons)[salesforce/handlebars-php

Handlebars processor for php

80713.2k11](/packages/salesforce-handlebars-php)[thomaswelton/gravatarlib

A lightweight PHP 5.3 OOP library providing easy gravatar integration.

251.1M5](/packages/thomaswelton-gravatarlib)[voodoophp/handlebars

Handlebars processor for php

34158.9k2](/packages/voodoophp-handlebars)

PHPackages © 2026

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