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.
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 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 jays-de/handlebars-bundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Shoot aims to make providing data to your templates more manageable
Handlebars processor for php
Parse Handlebars templates to a spec-compliant AST with PHP.
The bundle for easy using json-rpc api on your project
A Processor for Markup written in PHP. Allows extraction of Markup into a data structure, orchestrated nested manipulation of said structure, and output as (optimized) Markup.
Bundle Symfony DaplosBundle
统计信息
- 总下载量: 90.19k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 9
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-01-13