zendexperts/ze-theme

ZeTheme 是一个允许您在多种主题之间切换的 Zend Framework 2 模块。该模块不包含任何主题,但您可以创建自己的主题。

dev-master / 1.0.x-dev 2018-12-06 07:48 UTC

This package is not auto-updated.

Last update: 2024-09-14 13:23:19 UTC


README

ZeTheme 是一个允许您在多种主题之间切换的 Zend Framework 2 模块。它允许开发者为网站创建各种主题,并在需要时切换它们。

您可以定义多个安装主题的文件夹,并定义帮助选择当前主题的适配器。默认情况下,当前主题根据配置文件显示,但该模块允许创建可以从会话、数据库字段或任何其他您保存的位置选择主题的适配器。

安装/使用

您可以通过向 composer.json 文件添加以下行使用 Composer 安装 ZeTheme:

"require": {
    "zendexperts/ze-theme": "dev-master"
}

然后运行 php composer.phar update 并在 application.config.php 文件下的 modules 部分添加 ZeTheme

文档

在模块的配置文件中,您可以设置应使用的默认主题,应搜索各种主题的目录列表以及选择当前主题使用的适配器,如下所示:

'ze_theme' => array(
    'default_theme' => 'default',
    'theme_paths' => array(
        __DIR__ . '/../themes/'
    ),
    'adapters' => array(
        'ZeTheme\Adapter\Configuration',
    ),
),

要启动基本主题,您只需将 examples/theme 文件夹中的 default 主题复制到 themes 文件夹,或者按照下面的教程创建一个新的主题。确保将 default_theme 选项设置为您的主题名称。

ZeTheme 使用适配器来获取应渲染的主题。默认情况下,使用 ZeTheme\Adapter\Configuration 类从配置文件中获取指定的默认主题。还有一个 Session 适配器,可以从 $_SESSION['ZeTheme'] 获取主题,以及一个 Route 适配器,允许您通过简单地更改配置为类似以下内容来为每个路由指定不同的主题:

'ze_theme' => array(
    'default_theme' => 'default',
    'theme_paths' => array(
        __DIR__ . '/../themes/'
    ),
    'routes'=>array(
        'back'=>array('home', 'blog')
    ),
    'adapters' => array(
        'ZeTheme\Adapter\Configuration',
        'ZeTheme\Adapter\Route',
    ),
),

在这种情况下,当匹配 homeblog 路由时将使用 back 主题。在其他所有情况下,应用程序将使用 default 主题。

要创建新的主题,只需在由 theme_paths 数组指定的目录之一中创建一个以新主题命名的文件夹,该文件夹应包含一个 config.php 文件,该文件应返回一个包含新主题中定义的视图路径的配置数组。

如果您有更复杂的主题设置,可以使用动态主题路径,如下所示:

'ze_theme' => array(
    'default_theme' => 'default',
    'custom_theme_path' => true,
    'theme_paths' => array(
        __DIR__ . '/../themes/{theme}/frontend/'
    ),
    ...

当然,这里的 {theme} 将被 $default_theme 替换

以下是此类文件的示例:

<?php
return array(
    'template_path_stack' => array(
        'default' => __DIR__ . '/view',
    ),
    'template_map' => array(
        'layout/layout'           => __DIR__ . '/view/layout/layout.phtml',
        'application/index/index' => __DIR__ . '/view/application/index/index.phtml',
        'error/404'               => __DIR__ . '/view/error/404.phtml',
        'error/index'             => __DIR__ . '/view/error/index.phtml', 
    ),
);