bigecko/laravel-theme

为 Laravel 4 简单的主题管理器。

dev-master 2014-05-29 09:46 UTC

This package is not auto-updated.

Last update: 2024-09-24 01:26:38 UTC


README

灵感来源于 lightgear/theme,但不依赖于特定的资源管理器。

安装

Composer require

"bigecko/laravel-theme": "dev-master"

服务提供者

'Bigecko\LaravelTheme\LaravelThemeServiceProvider',

别名

'Theme' => 'Bigecko\LaravelTheme\Facade',

用法

结构

├── public/
    └── themes/
        ├── mytheme/
        |   ├── js/
        |   ├── css/
        |   └── views/
        |
        └── anothertheme/

创建一个名为 public/themes 的新文件夹。

themes 中创建一个文件夹,使用您的主题名称,例如 mytheme

将您的主题模板文件放在 mytheme/views 中。

初始化主题

Theme::init('mytheme');

自定义路径

Theme::init('mytheme', array(
    'public_dirname' => 'allthemes',    // Base dirname for contain all themes, relative to public path.
    'views_path' => app_path('views'),  // Change the path to contain theme templates.
));

一旦您更改了 views_path,主题的子目录 views 就不再需要了,
只需在 views_path 中创建您的主题文件夹,并将模板放在其中。
例如: app/views/mytheme/hello.blade.php

代码示例

View::make('home');  // First find in 'public/themes/mytheme/views/'.
                     // If file not exist, will use default location 'app/views/'.


Theme::asset('js/a.js');  // 'http://domain/themes/mytheme/js/a.js'

Theme::publicPath('js/jquery.js')  // /path/to/project/public/themes/mytheme/js/jquery.js

Theme::name(); // Get current theme name.

也支持包模板覆盖,只需将包模板放在您的主题视图文件夹中。

为什么使用这个?

简单

  • 不需要更改代码来渲染模板,仍然使用 View::make
  • 没有资源管理或其他依赖。
  • 没有新的配置文件。
  • 只有几行代码,易于阅读。
  • 仅用于主题,没有其他职责。

待办事项

  • 添加单元测试。