2017 © Pedro Peláez
 

library laravel-handlebars

A Laravel 5 wrapper for LightnCandy for using the Handlebars (and Mustache) template engine.

image

proai/laravel-handlebars

A Laravel 5 wrapper for LightnCandy for using the Handlebars (and Mustache) template engine.

  • Tuesday, February 13, 2018
  • by markusjwetzel
  • Repository
  • 5 Watchers
  • 30 Stars
  • 32,357 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 9 Forks
  • 2 Open issues
  • 13 Versions
  • 6 % Grown

The README.md

Laravel Handlebars

Latest Stable Version Total Downloads Latest Unstable Version License, (*1)

This package allows you to use Handlebars (and Mustache) templates with Laravel. You can integrate Handlebars templates into Blade templates and you can even use the Blade language directives @lang and @choice in Handlebars templates., (*2)

It's the perfect choice, if you want to use the same templates in different languages (i. e. PHP and JavaScript) and/or server- and clientside. The compiling and rendering is veeery fast, because this package wraps the super fast template engine LightnCandy., (*3)

Installation

Laravel Handlebars is distributed as a composer package. So you first have to add the package to your composer.json file:, (*4)

  • For Laravel 6+:, (*5)

    "proai/laravel-handlebars": "^1.14"
    
  • For Laravel 5.5 to 5.8:, (*6)

    "proai/laravel-handlebars": "~1.8"
    
  • For Laravel 5.1 to 5.4:, (*7)

    "proai/laravel-handlebars": "~1.5.0"
    

Then you have to run composer update to install the package. Once this is completed, you have to add the service provider to the providers array in config/app.php:, (*8)

/*
 * Package Service Providers...
 */
ProAI\Handlebars\HandlebarsServiceProvider::class,

You can publish the package configuration with the following command:, (*9)

php artisan vendor:publish --tag=laravel-handlebars

Usage

Configuration

Most of the options in config/handlebars.php are also used by LightnCandy. So please have a look at the LightnCandy readme for more information., (*10)

Only the basedir option can't be set in this config file. Instead the package uses the paths option in config/view.php to define base directories and also the compiled option in the same file to define the directory for the compiled templates (i. e. the cache directory)., (*11)

In addition to the LightnCandy options there are the options language_helpers, optional_raw_output and translate_raw_output. These options are described below., (*12)

Basics

You can use Handlebars templates the same way you use Blade templates. You can return them with View::make('articles', ['name' => 'Taylor']) or include them with the Blade @include directive, i. e. @include('articles', ['name' => 'Taylor'])., (*13)

By default all views which have a .hbs or .handlebars file extension are automatically detected as Handlebars templates. You can add more file extensions that should be treated as Handlebars templates in the fileext array in config/handlebars.php., (*14)

Language Helpers

If you wish, you can use the Blade language directives @lang and @choice in Handlebars templates, too. You have to set $language_helpers = true in order to use them. Here is an example:, (*15)

// Blade syntax:
@lang('message', ['firstname' => 'John', 'lastname' => $lastname])
@choice('comment_count', 2, ['item' => 'Article'])

```handlebars // Handlebars syntax: {{lang 'message' firstname='John' lastname=lastname }} {{choice 'comment_count' 2 item='Article' }}, (*16)


### Raw Output _This feature is currently broken. If you want to use it, use v1.1 or below or [help to fix it](https://github.com/ProAI/laravel-handlebars/issues/12)!_ If you want to output the raw code of a template (maybe because you want to use the unrendered template clientside), you can set `$optional_raw_output = true` in the configuration. Then you can pass a variable `$raw = true` to the template or more comfortable you can use the `@raw` Blade directive. ```php // Passing the $raw variable to the view: View::make('articles', ['raw' => true]) @include('articles', ['raw' => true])

```php // Blade @raw directive: @raw('articles'), (*17)


If you want to output a raw template with compiled and rendered language variables, you can set `$translate_raw_output = true`. ### Partials This package automatically adds the directory of the current template to the basedir of LightnCandy. By that it is possible to easily include other Handlebars templates in the same directory. Just write `{{> comment}}` to include `comment.hbs` from the same directory. ### Example Template ```handlebars {{#each array_variable }} {{#if this }} {{ output_some_variable }} {{> include_templatename }} {{else}} {{lang 'language_variable' }} {{/if}} {{/each}}

For more information about the Handlebars syntax see the Handlebars documentation. It does not matter that the examples are for JavaScript, because Handlebars templates are the same for JavaScript and PHP., (*18)

Using it with Webpack

If you want to use this package client side with webpack, have a look at this article:, (*19)

Sharing templates between PHP and JavaScript in Laravel, (*20)

Support

Bugs and feature requests are tracked on GitHub., (*21)

License

This package is released under the MIT License., (*22)

The Versions

13/02 2018

dev-master

9999999-dev http://github.com/proai/laravel-handlebars

A Laravel 5 wrapper for LightnCandy for using the Handlebars (and Mustache) template engine.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Markus J. Wetzel
by Manuel Wieser

laravel handlebars mustache template engine lightncandy

12/12 2017

1.8.0

1.8.0.0 http://github.com/proai/laravel-handlebars

A Laravel 5 wrapper for LightnCandy for using the Handlebars (and Mustache) template engine.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Markus J. Wetzel
by Manuel Wieser

laravel handlebars mustache template engine lightncandy

11/09 2017

1.7.0

1.7.0.0 http://github.com/proai/laravel-handlebars

A Laravel 5 wrapper for LightnCandy for using the Handlebars (and Mustache) template engine.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Markus J. Wetzel
by Manuel Wieser

laravel handlebars mustache template engine lightncandy

31/08 2017

1.6.0

1.6.0.0 http://github.com/proai/laravel-handlebars

A Laravel 5 wrapper for LightnCandy for using the Handlebars (and Mustache) template engine.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Markus J. Wetzel
by Manuel Wieser

laravel handlebars mustache template engine lightncandy

04/04 2017

1.5.0

1.5.0.0 http://github.com/proai/laravel-handlebars

A Laravel 5 wrapper for LightnCandy for using the Handlebars (and Mustache) template engine.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Markus J. Wetzel
by Manuel Wieser

laravel handlebars mustache template engine lightncandy

08/02 2017

1.4.0

1.4.0.0 http://github.com/proai/laravel-handlebars

A Laravel 5 wrapper for LightnCandy for using the Handlebars (and Mustache) template engine.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Markus J. Wetzel
by Manuel Wieser

laravel handlebars mustache template engine lightncandy

14/10 2016

1.3.2

1.3.2.0 http://github.com/proai/laravel-handlebars

A Laravel 5 wrapper for LightnCandy for using the Handlebars (and Mustache) template engine.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Markus J. Wetzel
by Manuel Wieser

laravel handlebars mustache template engine lightncandy

06/10 2016

1.3.1

1.3.1.0 http://github.com/proai/laravel-handlebars

A Laravel 5 wrapper for LightnCandy for using the Handlebars (and Mustache) template engine.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Markus J. Wetzel

laravel handlebars mustache template engine lightncandy

17/08 2016

1.3.0

1.3.0.0 http://github.com/proai/laravel-handlebars

A Laravel 5 wrapper for LightnCandy for using the Handlebars (and Mustache) template engine.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Markus J. Wetzel

laravel handlebars mustache template engine lightncandy

09/08 2016

1.2.0

1.2.0.0 http://github.com/proai/laravel-handlebars

A Laravel 5 wrapper for LightnCandy for using the Handlebars (and Mustache) template engine.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Markus J. Wetzel

laravel handlebars mustache template engine lightncandy

17/01 2016

1.1.0

1.1.0.0 http://github.com/proai/laravel-handlebars

A Laravel 5 wrapper for LightnCandy for using the Handlebars (and Mustache) template engine.

  Sources   Download

MIT

The Requires

 

by Markus J. Wetzel

laravel handlebars mustache template engine lightncandy

04/07 2015

1.0.1

1.0.1.0 http://github.com/proai/laravel-handlebars

A Laravel 5 wrapper for LightnCandy for using the Handlebars (and Mustache) template engine.

  Sources   Download

MIT

The Requires

 

by Markus J. Wetzel

laravel handlebars mustache template engine lightncandy

21/06 2015

1.0.0

1.0.0.0 http://github.com/proai/laravel-handlebars

A Laravel 5 wrapper for LightnCandy for using the Handlebars (and Mustache) template engine.

  Sources   Download

MIT

The Requires

 

by Markus J. Wetzel

laravel handlebars mustache template engine lightncandy