xorock/zend-phptal

为 Zend Framework 3 集成的 PHPTAL

0.1.1 2016-08-28 19:29 UTC

This package is not auto-updated.

Last update: 2024-09-14 18:04:21 UTC


README

提供对 PHPTAL 的集成,用于 Zend Framework 3

安装

使用 composer 安装此库

$ composer require xorock/zend-phptal

然后,将 ZfPhptal 添加到您的模块配置中的 modules 键下。

配置

以下配置选项(针对 PHPTAL)由 Service Factory 消费

return [
    'zfphptal' => [
        'cache_dir' => 'path to cached templates',
        // if enabled, delete all template cache files before processing
        'cache_purge_mode' => boolean,
        // set how long compiled templates and phptal:cache files are kept; in days 
        'cache_lifetime' => 30,
        'encoding' => 'set input and ouput encoding; defaults to UTF-8',
        // one of the predefined constants: PHPTAL::HTML5,  PHPTAL::XML, PHPTAL::XHTML
        'output_mode' => PhptalEngine::HTML5,
        // set whitespace compression mode
        'compress_whitespace' => boolean,
        // strip all html comments
        'strip_comments' => boolean,
        // if enabled, forces to reparse templates every time
        'debug' => boolean,
    ],
];

使用 Zend Framework 视图辅助工具

PhptalRenderer 通过 public function plugin($name, array $options = null) 或直接使用 __call() 代理到 HelperPluginManager

<a tal:attributes="href php: this.url('sample_route')">link</a>

您可以使用 ZF 的 'view_helpers' 选项键在全局/模块配置中注册自己的插件。例如,要注册 Test 插件

module.config.php

return [
    'view_helpers' => [
        'aliases' => [
            'test' => \My\View\Helper\Test::class,
        ],
        'factories' => [
            \My\View\Helper\Test::class => \Zend\ServiceManager\Factory\InvokableFactory::class
        ],
    ],
];


// inside template
// ${php: this.test()}

示例

骨架应用程序的示例 .html 文件可以在 examples 文件夹中找到。

与 ZTAL 的向后兼容性

为了与 ZTAL 项目 的渲染器向后兼容,注册了大量的标准变量。

$this->engine->set('doctype', $this->plugin('Doctype'));
$this->engine->set('headTitle', $this->plugin('HeadTitle'));
$this->engine->set('headScript', $this->plugin('HeadScript'));
$this->engine->set('headLink', $this->plugin('HeadLink'));
$this->engine->set('headMeta', $this->plugin('HeadMeta'));
$this->engine->set('headStyle', $this->plugin('HeadStyle'));