radicaldrew/slim-handlebars 问题修复 & 功能扩展

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

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

radicaldrew/slim-handlebars

Composer 安装命令:

composer require radicaldrew/slim-handlebars

包简介

Handlebars View Parser package for the Slim Framework based on jayc89/slim-handlebars

README 文档

README

Repository built from original jayc89/slim-handlebars, kudos to jayc89 thank you for the great start. There was a bunch of things I needed with Handlebars and Slim that was not possible to do without modifying the orginal code. I added and made sure you can use custom extensions. I also added the ability to add your own helpers using a addHelper method. This repository contains a custom View class for Handlebars (https://github.com/mardix/Handlebars). You can use the custom View class by either requiring the appropriate class in your Slim Framework bootstrap file and initialize your Slim application using an instance of the selected View class or using Composer (the recommended way).

How to Install

using Composer

Create a composer.json file in your project root:

{
    "require": {
        "radicaldrew/slim-handlebars": "dev-master"
    }
}

Then run the following composer command:

$ php composer.phar install

How to use

<?php
require 'vendor/autoload.php';

$app = new \Slim\Slim(array(
    'view' => new \Slim\Handlebars\Handlebars()
));

To use Handlebars options do the following:

$view = $app->view();
$view->setTemplatesDirectory('./views');
$view->parserOptions = array(
    'partialsDirectory' => './views/partials',
    'templateExtension' => 'html'
);

Templates (suffixed with .html in the example above) are assumed to be located within /templates. An optional sub-directory of partials (/templates/partials) can also be used.

To render the templates within your routes:

$app->get('/', function () use ($app) {
    $array = array();
    $app->render("home", $array);
});

How to add Registered Helpers

$view = $app->view();
$view->addHelper("upper",function($template, $context, $args, $source){
                                return strtoupper($context->get($args));
                         });

Authors

Andrew Karp

based on this original repistory Jamie Cressey

License

MIT Public License

统计信息

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

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-03-24