maxnuf/maxnuf-smarty

Zend Framework 2 模块,提供Smarty渲染策略、函数和修饰符,以便从模板渲染操作

v0.1 2013-04-13 13:39 UTC

This package is not auto-updated.

Last update: 2024-09-28 14:12:05 UTC


README

MaxnufSmarty 是一个模块,它将 Smarty 模板引擎与 Zend Framework 2 集成。

安装

  1. "maxnuf/maxnuf-smarty": "dev-master" 添加到您的 composer.json 文件中,并运行 php composer.phar update
  2. MaxnufSmarty 添加到您的 config/application.config.php 文件中的 modules 键下。

配置

可以通过 maxnufsmarty 配置键来设置配置。

'maxnufsmarty' => array(
    'config' => array(
        'compile_dir' => __DIR__ . '/../../data/Smarty/smarty_compile/',
        'cache_dir' => __DIR__ . '/../../data/Smarty/smarty_cache/',
    ),
),

MaxnufSmarty 与视图管理器服务集成,并使用在该服务中定义的相同解析器。对于 template_map,它查找配置中定义后缀的文件,默认为 .tpl。这允许您在视图管理器中定义模板路径堆栈和映射,而无需在安装模块时再次设置

'view_manager' => array(
    'template_path_stack'   => array(
        'application'              => __DIR__ . '/../templates',
    ),
    'template_map' => array(
        'layouts/layout'    => __DIR__ . '/../templates/layouts/layout.tpl',
        'index/index'       => __DIR__ . '/../templates/application/index/index.tpl',
    ),
), 

文档

视图助手

添加了对Zend视图助手的函数和修饰符的支持

在适当的情况下,可以将Zend视图助手作为函数或修饰符调用

{$form->get('title')|formLabel}
{$form->get('title')|formInput}
{url name="blog/view" params=['id'=>$item->id, 'title'=>$item->title]}

也可以使用 $this 调用Zend视图助手

{$this->formInput($form->get('title'))}

{$this->headTitle()->setSeperator(' - ')}

可以使用smarty修饰符 cat 来连接两个变量

{$this->headLink()->prependStylesheet($this->basePath()|cat:'/mystyle.css')}