PHPackages                             truemedia/handlelars - 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. truemedia/handlelars

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

truemedia/handlelars
====================

A Laravel 5 wrapper for Handlebars

5.0.5(11y ago)1110[1 issues](https://github.com/Truemedia/handlelars/issues)MITPHPPHP &gt;=5.4.0

Since Sep 20Pushed 11y ago1 watchersCompare

[ Source](https://github.com/Truemedia/handlelars)[ Packagist](https://packagist.org/packages/truemedia/handlelars)[ Docs](https://github.com/brightmachine/laratash)[ RSS](/packages/truemedia-handlelars/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (4)Versions (7)Used By (0)

handlelars
==========

[](#handlelars)

A Laravel wrapper for [Lightncandy](https://github.com/zordius/lightncandy), a PHP implementation of

Acknowledgements
================

[](#acknowledgements)

- Original credit to the creator of this repo , all I did was rename everything to handlebars and configure the handlebars PHP library.

Supports
--------

[](#supports)

- `Laravel 5`
- `Handlebars 2.0+`

Installation
============

[](#installation)

Add handlelars as a dependency to your `composer.json` file:

```
"require": {
	"laravel/framework":      "~5.0",
	"truemedia/handlelars": "dev-master"
}
```

run `composer update`, or `composer install` if this is a brand new project

Add the Service Provider
------------------------

[](#add-the-service-provider)

Open: `config/app.php`

```
...

'Handlelars\HandlelarsServiceProvider',

...
```

You are all setup!

Usage
=====

[](#usage)

Handlelars is merely a wrapper for the [Lightncandy](https://github.com/zordius/lightncandy) library that integrates it into Laravel 5+.

Handlelars registers itself with the Laravel View class, providing seamless integration with Laravel. You can use Handlebars just as you would Blade! The Laravel View class will choose the right template engine to use based on the file extension of the view. So all you have to do to render Handlebars files, is ensure that your view has a `.hbs` file extension. Handlelars will take care of the rest.

You can even mix and match template engines. For instance maybe you have a Blade layout file, and you want to nest a Handlebars view, that's fine! The Handlebars view will be rendered into a variable named whatever section you passed the view to. So for example if you were to do:

```
$view->nest('content', 'some.view');
$view->nest('sidebar', 'some.sidebar');
```

The contents of the parsed `some.view` file will be available in the template file under a variable called `$content`. The contents of the parsed `some.sidebar` would be available in the template file, under a variable called `$sidebar`.

By default, Handlebars partials are also loaded using Laravel's ViewFinder, so you can feel free to use dot-notation to specify a view.

```
{{#posts}}
	{{> posts._post}}
{{/posts}}
```

Other than that it is business as usual!

Examples:
=========

[](#examples)

- Example using View::make()

    app/views/test.hbs

    ```
      {{ pageHeading }}

      	{{ pageContent }}

    ```

    app/router.php

    ```
      Route::get('/', function()
      {
      	return View::make('test', array(
      		'pageHeading' => 'Rendered with Lightncandy',
      		'pageContent' => 'But still looks like Laravel!'
      	));
      });

    ```
- Example using a Blade controller layout

    app/views/layouts/master.blade.php

    ```

      	{{ content }}

    ```

    app/views/test.mustache

    ```
      {{ pageHeading }}

      	{{ pageContent }}

    ```

    app/controllers/TestController.php

    ```
