kucherenko/silex-xsltemplate

SilexXSLTemplate\ServiceProvider 提供了 Silex 微型框架与 XSLTemplate 模板引擎的集成。

dev-master / 1.0.x-dev 2012-10-05 10:38 UTC

This package is not auto-updated.

Last update: 2024-09-28 13:27:08 UTC


README

SilexXSLTemplate\ServiceProvider 提供了 Silex 微型框架与 XSLTemplate 模板引擎的集成。

支持 PHP 5.3.2 或更高版本。

参数

  • xsltemplate.templates.path: 包含 xsl 模板文件的目录路径。
  • xsltemplate.templates.url: XSL 模板的 HTTP URL。
  • xsltemplate.parameters (可选): xsltemplate 参数的关联数组。有关更多信息,请参阅 xsltemplate 文档。

服务

  • xsltemplate: XSLTemplate\Renderer 实例。与 XSLTemplate 交互的主要方式。
  • xsltemplate.writer: XSLTemplate\XML\Writer 实例。用于收集模板数据的 xml 格式对象。
  • xsltemplate.configure: 接收 XSLTemplate 环境作为参数的保护闭包。您可以使用它来添加更多自定义全局变量。

注册

请确保在 vendor/xsltemplate 目录中放置 XSLTemplate 的副本。

$app->register(new SilexXSLTemplate\ServiceProvider(), array(
    'xsltemplate.templates.path' => __DIR__ . '/xsl',
    'xsltemplate.templates.url'  => 'xsl/',
    'xsltemplate.class_path'     => __DIR__ . '/vendor/xsltemplate/src',
));

用法

XSLTemplate 提供商提供了一个 xsltemplate 服务

$app->get('/hello/{name}', function ($name) use ($app) {

    $app['xsltemplate.writer']->writeElement('page', 'test');

    $content = $app['xsltemplate']->render('hello.xsl', $app['xsltemplate.writer']);
    $contentType = $app['xsltemplate']->getContentType();

    return new Symfony\Component\HttpFoundation\Response(
        $content,
        200,
        array('Content-Type' => $contentType)
    );
});

这将渲染一个名为 xsl/hello.xsl 的文件。

有关更多信息,请参阅 XSLTemplate 文档