shapecode/theme-bundle

该软件包已被废弃,不再维护。未建议替代软件包。

为 Symfony Bundles 提供主题支持

安装: 205

依赖项: 0

建议者: 0

安全: 0

星标: 1

关注者: 1

分支: 0

开放问题: 0

类型:symfony-bundle

dev-master / 1.0.x-dev 2019-07-22 08:36 UTC

This package is auto-updated.

Last update: 2020-11-21 19:15:58 UTC


README

此软件包为您提供向每个软件包添加主题的可能性。在您的软件包目录中,它将在 Resources/themes/<themename> 下查找,如果未找到匹配的文件,将回退到常规 Resources/views。

安装

安装是一个快速(我保证!)的 3 步过程

  1. 下载 ShapecodeThemeBundle
  2. 启用软件包

步骤 1:使用 Composer 安装 ShapecodeThemeBundle

运行以下 composer require 命令

$ php composer.phar require shapecode/theme-bundle

步骤 2:启用软件包

最后,在内核中启用该软件包

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new \Shapecode\Bundle\ThemeBundle\ShapecodeThemeBundle(),
    );
}

配置

您需要设置可能的主题以及当前活动主题。活动主题必须是主题列表的一部分。

# app/config/config.yml
shapecode_theme:
    themes: ['standardTheme', 'winter_theme', 'weekend']
    active_theme: 'standardTheme'

从 Cookie 获取活动主题信息

如果您想根据 Cookie 选择活动主题,可以添加

# app/config/config.yml
shapecode_theme:
    cookie:
        name: NameOfTheCookie
        lifetime: 31536000 # 1 year in seconds
        path: /
        domain: ~
        secure: false
        http_only: false

主题层叠顺序

以下顺序在检查位于软件包中的模板时适用,例如具有主题名称 phone@BundleName/Resources/template.html.twig 位于

  1. 覆盖主题目录: app/Resources/themes/phone/BundleName/template.html.twig
  2. 覆盖视图目录: app/Resources/BundleName/views/template.html.twig
  3. 软件包主题目录: src/BundleName/Resources/themes/phone/template.html.twig
  4. 软件包视图目录: src/BundleName/Resources/views/template.html.twig

例如,如果您想集成有关您的主题架构的某些 TwigBundle 自定义错误页面,您必须使用此目录结构: app/Resources/themes/phone/TwigBundle/Exception/error404.html.twig

以下顺序在检查应用程序范围的基础模板时适用,例如具有主题名称 phone::template.html.twig 位于

  1. 覆盖主题目录: app/Resources/themes/phone/template.html.twig
  2. 覆盖视图目录: app/Resources/views/template.html.twig

更改主题层叠顺序

您可以通过配置指令更改层叠顺序: path_patterns.app_resourcepath_patterns.bundle_resourcepath_patterns.bundle_resource_dir。例如

# app/config/config.yml
shapecode_theme:
    path_patterns:
        app_resource:
            - %%app_path%%/themes/%%current_theme%%/%%template%%
            - %%app_path%%/themes/fallback_theme/%%template%%
            - %%app_path%%/views/%%template%%
        bundle_resource:
            - %%bundle_path%%/Resources/themes/%%current_theme%%/%%template%%
            - %%bundle_path%%/Resources/themes/fallback_theme/%%template%%
        bundle_resource_dir:
            - %%dir%%/themes/%%current_theme%%/%%bundle_name%%/%%template%%
            - %%dir%%/themes/fallback_theme/%%bundle_name%%/%%template%%
            - %%dir%%/%%bundle_name%%/%%override_path%%
层叠顺序模式占位符
占位符 表示 示例
%app_path% 应用程序资源所在的路径 app/Resources
%bundle_path% 软件包所在的路径,例如 src/Vendor/CoolBundle/VendorCoolBundle
%bundle_name% 软件包的名称 VendorCoolBundle
%dir% 资源应首先查找的目录
%current_theme% 当前活动主题的名称
%template% 模板名称 view.html.twig
%override_path% 与模板相同,但包含视图目录 views/list.html.twig

更改活动主题

关于这个问题,请查看ThemeRequestListener。

如果您处于请求周期的早期阶段并且尚未渲染任何模板,您仍然可以更改主题而不会出现问题。为此,主题服务存在于

$activeTheme = $container->get('shapecode_theme.active_theme');
echo $activeTheme->getName();
$activeTheme->setName("phone");

贡献

欢迎积极贡献和补丁。

首先安装依赖项

   composer.phar install --dev