jays-de/handlebars-bundle 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

jays-de/handlebars-bundle

Composer 安装命令:

composer require jays-de/handlebars-bundle

包简介

This Symfony bundle provides integration for the handlebars template engine.

README 文档

README

This Symfony bundle provides integration for the Handlebars template engine using LightnCandy as renderer.

Build Status Scrutinizer Scrutinizer Packagist SensioLabsInsight

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

    # app/config/config.yml
    framework:
        templating:      { engines: ['twig', 'handlebars'] }

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', [...]);
    }

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

 # app/config/config.yml
handlebars:
  flags:
    - FLAG_BESTPERFORMANCE
  excludedFlags:
    - FLAG_STANDALONE

Helper functions

Built-In helpers

The Bundle comes with some built-in helpers.

Linking to pages

Use the path helper and refer to the route

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

Its also possible to add parameters to the referenced route

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

You can also generate an absolute URL using the url helper

<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.

<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.

Example:

<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

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

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

See also the list of contributors who participated in this project.

Submitting bugs and feature requests

Bugs and feature requests are tracked on GitHub.

jays-de/handlebars-bundle 适用场景与选型建议

jays-de/handlebars-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 90.19k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2016 年 01 月 13 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「templating」 「symfony」 「handlebars」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 jays-de/handlebars-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 jays-de/handlebars-bundle 我们能提供哪些服务?
定制开发 / 二次开发

基于 jays-de/handlebars-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 90.19k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 9
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 2
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-01-13