2017 © Pedro Peláez
 

symfony-bundle handlebars-bundle

This Symfony bundle provides integration for the handlebars template engine.

image

jays-de/handlebars-bundle

This Symfony bundle provides integration for the handlebars template engine.

  • Wednesday, June 13, 2018
  • by jays-de
  • Repository
  • 2 Watchers
  • 4 Stars
  • 27,155 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 4 Forks
  • 1 Open issues
  • 26 Versions
  • 13 % Grown

The README.md

HandlebarsBundle

This Symfony bundle provides integration for the Handlebars template engine using LightnCandy as renderer., (*1)

Build Status Scrutinizer Scrutinizer Packagist SensioLabsInsight, (*2)

Installation

Prerequisites

  • Symfony 2.8+
  • composer

Installation

composer require jays-de/handlebars-bundle

Composer will install the bundle to your project's `vendor/` directory.

### 2. Enable the bundle

Enable the bundle in the kernel:

``` php
<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new \JaySDe\HandlebarsBundle\HandlebarsBundle();
    );
}

3. Enable the Handlebars template engine in the config

``` yaml # app/config/config.yml framework: templating: { engines: ['twig', 'handlebars'] }, (*3)


Documentation ------------- ### Usage Files in your Resources/view with a .hbs or .handlebars ending are supported.

public function indexAction(Request $request) { ... return $this->render('index.hbs', [...]); }, (*4)


This will render the file index.hbs in your `Resources/views` folder. ### Configuration flags It's possible to set or unset the different flags provided by LightnCandy. Therefore set in your config.yml the fields flags and excludedFlags. The bundle will ensure that default flags are set, to prevent a non working template engine. The complete list of flags can be found at the [LnC documentation](https://github.com/zordius/lightncandy#compile-options) ```yaml # app/config/config.yml handlebars: flags: - FLAG_BESTPERFORMANCE excludedFlags: - FLAG_STANDALONE

Helper functions

Built-In helpers

The Bundle comes with some built-in helpers., (*5)

Linking to pages

Use the path helper and refer to the route, (*6)

<a href="{{route_path '_welcome' }}">Home</a>

Its also possible to add parameters to the referenced route, (*7)

<a href="{{route_path 'article_show' slug=article.slug}}">{{ article.title }}</a>

You can also generate an absolute URL using the url helper, (*8)

<a href="{{route_url '_welcome' }}">Home</a>
Linking to assets

To avoid hardcoding pathes to assets like images, javascript or stylesheets use the asset helper., (*9)

<img src="{{asset 'images/logo.png' }}" />

<link href="{{asset 'css/blog.css' }}" rel="stylesheet" />

Adding new Helpers

To add new helper functions to the handlebars engine, you just have to create a class implementing JaySDe\HandlebarsBundle\Helper\HelperInterface and create a service definition with the tag handlebars.helper. The ID of the tag is the helpers block name inside handlebars templates., (*10)

Example:, (*11)

<service id="handlebars.helper.trans" class="JaySDe\HandlebarsBundle\Helper\TranslationHelper">
    <tag name="handlebars.helper" id="i18n" />
    <argument type="service" id="translator" />
</service>

The helper registry also supports to register any callable. So it's possible to create a class with the magic __invoke() method and define a service for it, (*12)

class MyHelper{
    public function __invoke($context, $options) {}
}
<service id="handlebars.helper.my" class="MyHelper">
    <tag name="handlebars.helper" id="my" />
</service>

or using a factory method returning an anonymous function for example, (*13)

class HelperFactory{
    public function getMyHelper() {
        return function($context, $options) {}
    }
}
<services>
    <service id="handlebar.helper_factory" class="HelperFactory" />
    <service id="handlebars.helper.my" class="callable">
        <factory service="handlebar.helper_factory" method="getMyHelper" />
        <tag name="handlebars.helper" id="my" />
    </service>
</services>

Authors

Jens Schulze - jens.schulze@commercetools.de, (*14)

See also the list of contributors who participated in this project., (*15)

Submitting bugs and feature requests

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

The Versions

23/08 2016

dev-update_to_recent_version

dev-update_to_recent_version https://github.com/jayS-de/HandlebarsBundle

This Symfony bundle provides integration for the handlebars template engine.

  Sources   Download

MIT

The Requires

 

The Development Requires

templating symfony handlebars

18/08 2016

dev-patch-1

dev-patch-1 https://github.com/jayS-de/HandlebarsBundle

This Symfony3 bundle provides integration for the handlebars template engine.

  Sources   Download

MIT

The Requires

 

The Development Requires

templating symfony handlebars

20/07 2016

0.8.0

0.8.0.0 https://github.com/jayS-de/HandlebarsBundle

This Symfony3 bundle provides integration for the handlebars template engine.

  Sources   Download

MIT

The Requires

 

The Development Requires

templating symfony handlebars

05/07 2016

0.7.0

0.7.0.0 https://github.com/jayS-de/HandlebarsBundle

This Symfony3 bundle provides integration for the handlebars template engine.

  Sources   Download

MIT

The Requires

 

The Development Requires

templating symfony handlebars

08/06 2016

0.6.0

0.6.0.0 https://github.com/jayS-de/HandlebarsBundle

This Symfony3 bundle provides integration for the handlebars template engine.

  Sources   Download

MIT

The Requires

 

The Development Requires

templating symfony handlebars

08/06 2016

0.5.0

0.5.0.0 https://github.com/jayS-de/HandlebarsBundle

This Symfony3 bundle provides integration for the handlebars template engine.

  Sources   Download

MIT

The Requires

 

The Development Requires

templating symfony handlebars

18/04 2016

0.4.2

0.4.2.0 https://github.com/jayS-de/HandlebarsBundle

This Symfony3 bundle provides integration for the handlebars template engine.

  Sources   Download

MIT

The Requires

 

The Development Requires

templating symfony handlebars

14/04 2016

0.4.1

0.4.1.0 https://github.com/jayS-de/HandlebarsBundle

This Symfony3 bundle provides integration for the handlebars template engine.

  Sources   Download

MIT

The Requires

 

The Development Requires

templating symfony handlebars

08/04 2016

0.4.0

0.4.0.0 https://github.com/jayS-de/HandlebarsBundle

This Symfony3 bundle provides integration for the handlebars template engine.

  Sources   Download

MIT

The Requires

 

The Development Requires

templating symfony handlebars

31/03 2016

0.3.0

0.3.0.0 https://github.com/jayS-de/HandlebarsBundle

This Symfony3 bundle provides integration for the handlebars template engine.

  Sources   Download

MIT

The Requires

 

The Development Requires

templating symfony handlebars

11/03 2016

0.2.1

0.2.1.0 https://github.com/jayS-de/HandlebarsBundle

This Symfony3 bundle provides integration for the handlebars template engine.

  Sources   Download

MIT

The Requires

 

The Development Requires

templating symfony handlebars

25/01 2016

0.2.0

0.2.0.0 https://github.com/jayS-de/HandlebarsBundle

This Symfony3 bundle provides integration for the handlebars template engine.

  Sources   Download

MIT

The Requires

 

The Development Requires

templating symfony handlebars

18/01 2016

0.1.1

0.1.1.0 https://github.com/jayS-de/HandlebarsBundle

This Symfony3 bundle provides integration for the handlebars template engine.

  Sources   Download

MIT

The Requires

 

The Development Requires

templating symfony handlebars

14/01 2016

0.1

0.1.0.0 https://github.com/jayS-de/HandlebarsBundle

This Symfony3 bundle provides integration for the handlebars template engine.

  Sources   Download

MIT

The Requires

 

The Development Requires

templating symfony handlebars