rych/silex-plates-provider

此包已被弃用且不再维护。未建议替代包。

为Silex提供Plates模板引擎。

v1.0.1 2014-07-27 12:39 UTC

This package is auto-updated.

Last update: 2021-09-23 04:58:03 UTC


README

本项目旨在将 Plates 模板引擎集成到 Silex 微框架 中。目前处于非常初期的阶段,因此如果集成效果不是最佳,请不要感到惊讶。

该项目在默认的 TwigServiceProvider 上非常依赖,并且使用了某些 Symfony-Twig 桥接扩展。

使用方法

将提供者添加到您的 composer.json 文件中

{
    "require": {
        "rych/silex-plates-provider": "1.0.*"
    }
}

在您的应用程序中启用它

<?php

/* @var $app Silex\Application */
$app->register(new \Rych\Silex\Provider\PlatesServiceProvider(), array (
    'plates.path' => '/path/to/templates', // Required
    'plates.folders' => array (            // Optional
        'email' => '/path/to/email/templates';
    ),
));

$app->get('/', function () use ($app) {
    return $app['plates']->render('mytemplate');
});

扩展

此提供者还注册了一些常见的扩展,这些扩展与在 Symfony-Twig 桥接中找到的类似。我希望未来能添加更多,但现在我只包括我经常使用的几个大扩展。

路由扩展

提供生成 URI 的 urlpath 函数。此扩展仅在注册了 UrlGeneratorServiceProvider 时可用。

安全扩展

提供 is_granted 函数。此扩展仅在注册了 SecurityServiceProvider 时可用。

自定义扩展

您可以选择注册自己的 Plates 扩展。这可以通过扩展 plates.engine 服务轻松完成。

<?php

/* @var $app Silex\Application */
$app['plates.engine'] = $app->share($app->extend('plates.engine', function($engine, $app) {
    $engine->addExtension(new \My_Plates_Extension());

    return $engine;
}));