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

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

eden/handlebars
===============

PHP Handlebars with JS interface to match with compile time helper support and super nice compile time error reporting.

5.0.0(10y ago)27.9k11MITPHPPHP &gt;=5.4.1

Since Oct 9Pushed 10y ago4 watchersCompare

[ Source](https://github.com/Eden-PHP/Handlebars)[ Packagist](https://packagist.org/packages/eden/handlebars)[ Docs](http://eden-php.com)[ RSS](/packages/eden-handlebars/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (7)Dependencies (1)Versions (9)Used By (1)

[![logo](https://camo.githubusercontent.com/683ba05b2b51f50045c674b19a4f0ceb30702a8ab495623be7c02e07ab226f08/687474703a2f2f6564656e2e6f70656e6f766174652e636f6d2f6173736574732f696d616765732f636c6f75642d736f6369616c2e706e67)](https://camo.githubusercontent.com/683ba05b2b51f50045c674b19a4f0ceb30702a8ab495623be7c02e07ab226f08/687474703a2f2f6564656e2e6f70656e6f766174652e636f6d2f6173736574732f696d616765732f636c6f75642d736f6369616c2e706e67) Eden Handlebars
=====================================================================================================================================================================================================================================================================================================================================================================================================================================================================

[](#-eden-handlebars)

[![Build Status](https://camo.githubusercontent.com/e680ed3250c13fc18f80724ede7ad1af66cf436a347cd545d4368b217333ea29/68747470733a2f2f6170692e7472617669732d63692e6f72672f4564656e2d5048502f48616e646c65626172732e706e67)](https://travis-ci.org/Eden-PHP/Handlebars)
====================================================================================================================================================================================================================================================================

[](#)

- [Install](#install)
- [Introduction](#intro)
- [Usage](#usage)
- [Features](#features)
- [De-Features](#defeatures)
- [Production Ready](#production)
- [API](#api)
    - [compile](#compile)
    - [getCache](#getCache)
    - [getHelper](#getHelper)
    - [getHelpers](#getHelpers)
    - [getPartial](#getPartial)
    - [getPartials](#getPartials)
    - [registerHelper](#registerHelper)
    - [registerPartial](#registerPartial)
    - [setPrefix](#setPrefix)
    - [setCache](#getPartials)
    - [unregisterHelper](#unregisterHelper)
    - [unregisterPartial](#unregisterPartial)
- [Contributing](#contributing)

====

Install
-------

[](#install)

`composer install eden/handlebars`

====

Enable Eden
-----------

[](#enable-eden)

The following documentation uses `eden()` in its example reference. Enabling this function requires an extra step as descirbed in this section which is not required if you access this package using the following.

```
Eden\Handlebars\Index::i();

```

When using composer, there is not an easy way to access functions from packages. As a workaround, adding this constant in your code will allow `eden()` to be available after.

```
Eden::DECORATOR;

```

For example:

```
Eden::DECORATOR;

eden()->inspect('Hello World');

```

====

Introduction
------------

[](#introduction)

PHP Handlebars with JS interface to match with compile time helper support and super nice compile time error reporting. This version of Handlebars is based on caching the compiled templates and inheritently made the overall compile times faster. Loading at ~50ms uncached and ~30ms cached.

====

Basic Usage
-----------

[](#basic-usage)

#### Rendering

[](#rendering)

```
$template = eden('handlebars')->compile('{{foo}} {{bar}}');

echo $template(array('foo' => 'BAR', 'bar' => 'ZOO'));

```

#### Registering Helpers

[](#registering-helpers)

```
$template = eden('handlebars')
	->registerHelper('bar', function($options) {
		return 'ZOO';
	})
	->compile('{{foo}} {{bar}}');

echo $template(array('foo' => 'BAR'));

```

#### Registering Partials

[](#registering-partials)

```
$template = eden('handlebars')
	->registerPartial('bar', 'zoo')
	->compile('{{foo}} {{> bar}}');

echo $template(array('foo' => 'BAR'));

```

====

Features
--------

[](#features)

- PHP API - designed to match the handlebars.js documentation
    - registerHelper() - Matches exactly what you expect from handlebars.js (except it's PHP syntax)
    - registerPartial() - accepts strings and functions as callbacks
    - Literals like `{{./foo}}` and `{{../bar}}` are evaluated properly
    - Comments like `{{!-- Something --}}` and `{{! Something }}` supported
    - Trims like `{{~#each}}` and `{{~foo~}}` supported
    - Mustache backwards compatibility `{{#foo}}{{this}}{{/foo}}`
    - Tokenizer helpers to optimize custom code generation to cache
    - Event handlers for unknown helpers and unknown partials
- Default Helpers matching handlebars.js
    - each - and `{{#each foo as |value, key|}}`
        - Please note that there is an issue with `each` being slow depending on the size of the object
        - We need help optimizing this
    - with
    - unless
    - if

De-Features (or whatever the opposite of features is)
-----------------------------------------------------

[](#de-features-or-whatever-the-opposite-of-features-is)

- Does not support file templates.
    - You need to load them up and pass it into Handlebars.
    - If this is a problem you should consider other Handlebars PHP libraries
    - You can always create a helper for this
    - This de-feature will be considered upon requests ( create an issue :) )
- Partial Failover
    - Something we haven't had a chance to come around doing yet as we did not have a need
    - This de-feature will be considered upon requests ( create an issue :) )
- Safe String/Escaping
    - PHP has functions that can turn a string "safe".
    - We didn't want to create something that already exists in other contexts
    - This de-feature will be considered upon requests ( create an issue :) )
- Utils
    - PHP has functions that support most of the listed Utils in handlebars.js
    - We didn't want to create something that already exists in other contexts
    - This de-feature will be considered upon requests ( create an issue :) )
- Dynamic Partials
    - At the bottom of our pipe
    - because of it's difficulty to recreate
    - and practicality
    - This de-feature will be considered upon requests ( create an issue :( )
- Inline Partials
    - TODO
- Decorators
    - TODO
- Frames
    - TODO

====

Production Ready
----------------

[](#production-ready)

When your templates are ready for a production (live) environment, it is recommended that caching be used. To enable cache:

- Create a cache folder and make sure permissions are properly set for handlebars to write files to it.
- Enable cache by using `eden('handlebars')->setCache(__DIR__.'/your/cache/folder/location');`
- If the folder location does not exist, caching will be disabled.

====

API
---

[](#api)

====

### compile

[](#compile)

Returns a callback that binds the data with the template

#### Usage

[](#usage)

```
eden('handlebars')->compile(string $string);

```

#### Parameters

[](#parameters)

- `string $string` - the template string

Returns `function` - the template binding handler

#### Example

[](#example)

```
eden('handlebars')->compile();

```

====

### getCache

[](#getcache)

Returns the active cache path

#### Usage

[](#usage-1)

```
eden('handlebars')->getCache();

```

Returns `Closure`

====

### getHelper

[](#gethelper)

Returns a helper given the name

#### Usage

[](#usage-2)

```
eden('handlebars')->getHelper('if');

```

#### Parameters

[](#parameters-1)

- `string $name` - the name of the helper

Returns `Closure`

====

### getHelpers

[](#gethelpers)

Returns all the registered helpers

#### Usage

[](#usage-3)

```
eden('handlebars')->getHelpers();

```

#### Parameters

[](#parameters-2)

Returns `array`

====

### getPartial

[](#getpartial)

Returns a partial given the name

#### Usage

[](#usage-4)

```
eden('handlebars')->getPartial('foobar');

```

#### Parameters

[](#parameters-3)

- `string $name` - the name of the partial

Returns `string`

====

### getPartials

[](#getpartials)

Returns all the registered partials

#### Usage

[](#usage-5)

```
eden('handlebars')->getPartials();

```

#### Parameters

[](#parameters-4)

Returns `array`

====

### registerHelper

[](#registerhelper)

The famous register helper matching the Handlebars API

#### Usage

[](#usage-6)

```
eden('handlebars')->registerHelper(string $name, function $helper);

```

#### Parameters

[](#parameters-5)

- `string $name` - the name of the helper
- `function $helper` - the helper handler

Returns `Eden\Handlebrs\Index`

#### Example

[](#example-1)

```
eden('handlebars')->registerHelper();

```

====

### registerPartial

[](#registerpartial)

Delays registering partials to the engine because there is no add partial method...

#### Usage

[](#usage-7)

```
eden('handlebars')->registerPartial(string $name, string $partial);

```

#### Parameters

[](#parameters-6)

- `string $name` - the name of the helper
- `string $partial` - the helper handler

Returns `Eden\Handlebrs\Index`

#### Example

[](#example-2)

```
eden('handlebars')->registerPartial();

```

====

### setCache

[](#setcache)

Enables the cache option

#### Usage

[](#usage-8)

```
eden('handlebars')->setCache(string $path);

```

#### Parameters

[](#parameters-7)

- `string $path` - The cache path

Returns `Eden\Handlebrs\Index`

#### Example

[](#example-3)

```
eden('handlebars')->setCache('/path/to/cache/folder');

```

====

### setPrefix

[](#setprefix)

Sets the file name prefix for caching

#### Usage

[](#usage-9)

```
eden('handlebars')->setPrefix(string $prefix);

```

#### Parameters

[](#parameters-8)

- `string $prefix` - Custom prefix name

Returns `Eden\Handlebrs\Index`

#### Example

[](#example-4)

```
eden('handlebars')->setPrefix('special-template-');

```

====

### unregisterHelper

[](#unregisterhelper)

The opposite of registerHelper

#### Usage

[](#usage-10)

```
eden('handlebars')->unregisterHelper(string $name);

```

#### Parameters

[](#parameters-9)

- `string $name` - the helper name

Returns `Eden\Handlebars\Index`

#### Example

[](#example-5)

```
eden('handlebars')->unregisterHelper();

```

====

### unregisterPartial

[](#unregisterpartial)

The opposite of registerPartial

#### Usage

[](#usage-11)

```
eden('handlebars')->unregisterPartial(string $name);

```

#### Parameters

[](#parameters-10)

- `string $name` - the partial name

Returns `Eden\Handlebars\Index`

#### Example

[](#example-6)

```
eden('handlebars')->unregisterPartial();

```

====

\#Contributing to Eden

Contributions to *Eden* are following the Github work flow. Please read up before contributing.

\##Setting up your machine with the Eden repository and your fork

1. Fork the repository
2. Fire up your local terminal create a new branch from the `v4` branch of your fork with a branch name describing what your changes are. Possible branch name types:
    - bugfix
    - feature
    - improvement
3. Make your changes. Always make sure to sign-off (-s) on all commits made (git commit -s -m "Commit message")

\##Making pull requests

1. Please ensure to run `phpunit` before making a pull request.
2. Push your code to your remote forked version.
3. Go back to your forked version on GitHub and submit a pull request.
4. An Eden developer will review your code and merge it in when it has been classified as suitable.

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity63

Established project with proven stability

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 ~26 days

Recently: every ~4 days

Total

9

Last Release

3664d ago

Major Versions

4.0.5 → v5.x-dev2016-05-07

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/120378?v=4)[Christian Blanquera](/maintainers/cblanquera)[@cblanquera](https://github.com/cblanquera)

---

Tags

librarytemplatetemplatingedenhamdlebars

### Embed Badge

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

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

###  Alternatives

[figdice/figdice

Template Engine, XML-centric and attribute-driven

222.4k1](/packages/figdice-figdice)

PHPackages © 2026

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