foreverglory/theme-bundle

Symfony ThemeBundle

v2.1.0 2016-03-19 10:33 UTC

This package is not auto-updated.

Last update: 2024-09-14 15:21:53 UTC


README

Symfony2 Bundle 用于主题选择,你可以设置主题目录、默认主题或通过类设置当前主题。自定义主题目录、模板文件规则

简介

Composer

将此包添加到项目中的 composer.json 文件的 require 部分

{
    "foreverglory/theme-bundle": "~2.0"
}

将此包添加到应用程序的内核中

//app/AppKernel.php
public function registerBundles()
{
    return array(
         // ...
        new Glory\Bundle\ThemeBundle\GloryThemeBundle(),
        // ...
    );
}

在 YAML 配置中配置服务

#app/config/config.yml
glory_theme:
    default: default        #default theme, Allow Null or One of theme list. (默认主题,允许为空或者下面配置中的一个主题)
    switch: ~               #switch theme, class, if exist use class->getChecked(); (切换主题,类,如果存在,则优先取该类所选择的主题,参考) see: ThemeBundle/Switcher/*, you can write class
    themes:                 #themes list
        default:            #theme name, theme dir
            dir: %kernel.root_dir%/Resources/desktop
            format: ~       #todo
        mobile:
            path: %kernel.root_dir%/Resources/mobile

PHP 示例

$themeManager = $container->get('glory_theme.manager');
$themeManager->getThemes();
$themeManager->getCurrentTheme();
$themeManager->getDefaultTheme();

待办事项

主题路径格式化,例如

app/Resources/TwigBundle/views/Exception/layout.html.twig

app/Resources       ==  theme dir
TwigBundle          ==  Bundle->getName()
views/Exception     ==  template path
layout.html.twig    ==  template file

我想格式化这个路径。