andrewslince/slim3-mustache-view

适用于Slim 3框架的PHP Mustache视图类

1.0.5 2016-11-27 12:34 UTC

This package is not auto-updated.

Last update: 2024-09-28 20:09:00 UTC


README

Build Status Latest Stable Version Scrutinizer Code Quality License

A PHP Mustache class for render views on Slim 3 Framework.

需求

  • Slim 3.0.0 或更高版本;
  • PHP 5.6 或更高版本。

安装

通过 Composer

$ composer require andrewslince/slim3-mustache-view

使用方法

<?php

$app = new \Slim\App([
    // your application settings
]);

// get application container
$container = $app->getContainer();

// register view template engine and configurations
$container['renderer'] = function () {
    return new \Slim\Views\Mustache([

        // REQUIRED
        'template' => [

            // REQUIRED
            'paths' => [
                realpath('./templates')
            ],

            // optional
            'extension' => 'html',

            // optional
            'charset' => 'utf-8',
        ],

        // put other mustache options here¹
    ]);
};

// use the render() method in your application routes
$app->get('/', function ($request, $response, $args) {

    // render your view
    return $this->renderer->render(
        $response,
        'index',
        $args
    );
});

$app->run();

注意

¹ 请参阅其他Mustache选项 此处.

测试

要运行单元测试,请执行以下命令

./vendor/bin/phpunit -c phpunit.xml.dist

贡献

请参阅 CONTRIBUTING 以获取详细信息。

致谢

许可协议

MIT许可协议(MIT)。请参阅 许可文件 以获取更多信息。