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

Abandoned → [https://github.com/gigglebox/dispatch-handlebars](/?search=https%3A%2F%2Fgithub.com%2Fgigglebox%2Fdispatch-handlebars)Library[Templating &amp; Views](/categories/templating)

giggleboxstudios/dispatch-handlebars
====================================

handlebars support for dispatch micro framework

1.0.0(11y ago)138[1 issues](https://github.com/GiggleboxStudios/dispatch-handlebars/issues)MITPHPPHP &gt;= 5.4.0

Since May 23Pushed 11y ago2 watchersCompare

[ Source](https://github.com/GiggleboxStudios/dispatch-handlebars)[ Packagist](https://packagist.org/packages/giggleboxstudios/dispatch-handlebars)[ Docs](https://github.com/GiggleboxStudios/dispatch-handlebars)[ RSS](/packages/giggleboxstudios-dispatch-handlebars/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (2)Versions (2)Used By (0)

{{handlebars}} for Dispatch
===========================

[](#handlebars-for-dispatch)

An extension for the [Dispatch](http://noodlehaus.github.io/dispatch/) PHP micro-framework that provides support for [Handlebars](http://handlebarsjs.com/) templates.

Requires:
---------

[](#requires)

```
{
  "require": {
    "php": ">= 5.4.0",
    "dispatch/dispatch": ">= 2.6.2",
    "xamin/handlebars.php": "dev-master"
  }
}
```

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

[](#installation)

This repo assumes you know how to install dependencies via [Composer](https://getcomposer.org/)

### composer.json:

[](#composerjson)

```
{
  "require": {
    "php": ">= 5.4.0",
    "dispatch/dispatch": ">= 2.6.2",
    "xamin/handlebars.php": "dev-master",
    "gigglebox/dispatch-handlebars": "dev-master"
  }
}
```

Open a new terminal to your working directory and `composer install` or `composer update`.

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

[](#configuration)

### your-main-app-file.php

[](#your-main-app-filephp)

```
  // main layout template file; must contain `{{{content}}}` in
  config('handlebars.layout') = 'layout';

  // set location of .handlbars templates (views and partials)
  config('handlebars.views') = 'path/to/tempaltes';

  // set character encoding for template files; defaults to `UTF-8`
  config('handlebars.charset') = 'utf-8';

  // prefix string to determine partial files, defaults to `_` (underscore)
  config('handlebars.partial_prefix') = '_';

  // [associative array](http://www.php.net/manual/en/language.types.array.php) of tagname and function names
  config('handlebars.helpers') = array('tagName' => 'callback_function');

  // path where compiled templates will be cached (this feature does not work yet)
  config('handlebars.cache') = 'path/to/cached/tempaltes';
```

> NOTE: If you do not define `handlebars.layout` and `handlebars.views`, handlebars will use the default `dispatch.layout` and `dispatch.views` values instead.

Using Handlebars with Dispatch
------------------------------

[](#using-handlebars-with-dispatch)

### layout.handlebars:

[](#layouthandlebars)

```
doctype html>

  {{#capitalize page.title }}

  {{{ content }}}

```

### homepage.handlebars:

[](#homepagehandlebars)

```

  Hello there, {{ user.notLoggedIn.name }}!
```

In our example `index.php` file, we'll use the `handlebars()` function to render our template within our route:

### index.php

[](#indexphp)

```
