2017 © Pedro Peláez
 

library handlebars-bundle

This bundle integrates rendering of Handlebars templates into Symfony2

image

smartive/handlebars-bundle

This bundle integrates rendering of Handlebars templates into Symfony2

  • Monday, January 9, 2017
  • by mfeltscher
  • Repository
  • 9 Watchers
  • 6 Stars
  • 18,539 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 3 Forks
  • 1 Open issues
  • 9 Versions
  • 4 % Grown

The README.md

Build Status Coverage Status Latest Stable Version Total Downloads License, (*1)

SmartiveHandlebarsBundle

Bundle to integrate Handlebars templates into your Symfony2 / Symfony3 application., (*2)

This bundle renders handlebars with the help of xamin/handlebars.php., (*3)

Installation

Require the smartive/handlebars-bundle package in your composer.json and update your dependencies., (*4)

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

Register the bundle in app/AppKernel.php:, (*5)

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

Configuration

Some of the features can be configured in the smartive_handlebars section of app/config/config.yml., (*6)

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):, (*7)

smartive_handlebars:
    templating:
        file_extension: .handlebars

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., (*8)

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:, (*9)

smartive_handlebars:
    templating:
        template_directories_recursive: false

Twig extension

The Handlebars Twig extension is enabled by default. To disable it add this to your configuration:, (*10)

smartive_handlebars:
    twig:
        enabled: false

Usage

Rendering service

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

Twig

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

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., (*13)

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:, (*14)

# 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:, (*15)

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

Caching

The rendering service offers the ability to cache the parsed template between requests for faster rendering., (*16)

You can enable caching by setting smartive_handlebars.cache to a existing cache service ID in your app/config/config.yml:, (*17)

smartive_handlebars:
    cache:
        enabled: true
        service: <service-id>

There are several caching services / strategies available per default:, (*18)

Disk

Service ID: smartive_handlebars.cache.disk, (*19)

Uses Handlebars\Cache\Disk to read/write file cache in Symfony's cache directory, (*20)

APC

Service ID: smartive_handlebars.cache.apc, (*21)

Uses Handlebars\Cache\APC to read/write cache objects using APC, (*22)

Redis

Service ID: smartive_handlebars.cache.redis, (*23)

Uses PhpRedis or Predis to read/write cache objects using a Redis Server. This bundle integrates with RedisBundle in order to make configuring your Redis implementation even easier. The default Redis client being used is snc_redis.default (see RedisBundle documentation)., (*24)

The default configuration can be overridden looks as follows:, (*25)

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

Custom

You can also define your own caching services by adding a class which implements Handlebars\Cache. To use your custom cache service you have to register it in your service configuration:, (*26)

# 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

# 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:'

The Versions

09/01 2017

dev-master

9999999-dev

This bundle integrates rendering of Handlebars templates into Symfony2

  Sources   Download

MIT

The Requires

 

The Development Requires

templating twig handlebars

09/01 2017
05/02 2016

1.3.0

1.3.0.0

This bundle integrates rendering of Handlebars templates into Symfony2

  Sources   Download

MIT

The Requires

 

The Development Requires

templating twig handlebars

27/01 2016

1.2.1

1.2.1.0

This bundle integrates rendering of Handlebars templates into Symfony2

  Sources   Download

MIT

The Requires

 

The Development Requires

templating twig handlebars

26/01 2016

1.2.0

1.2.0.0

This bundle integrates rendering of Handlebars templates into Symfony2

  Sources   Download

MIT

The Requires

 

The Development Requires

templating twig handlebars

10/12 2015

1.1.0

1.1.0.0

This bundle integrates rendering of Handlebars templates into Symfony2

  Sources   Download

MIT

The Requires

 

The Development Requires

templating twig handlebars

26/08 2015

1.0.0

1.0.0.0

This bundle integrates rendering of Handlebars templates into Symfony2

  Sources   Download

MIT

The Requires

 

The Development Requires

28/04 2015

0.2.0

0.2.0.0

This bundle integrates rendering of Handlebars templates into Symfony2

  Sources   Download

MIT

The Requires

 

The Development Requires

09/04 2015

0.1.0

0.1.0.0

This bundle integrates rendering of Handlebars templates into Symfony2

  Sources   Download

MIT

The Requires

 

The Development Requires