nwidart/themify
Composer 安装命令:
composer require nwidart/themify
包简介
Add basic theme functionality to a Laravel application.
README 文档
README
Themify is a Laravel package that provides basic theme functionality in a non-obtrusive way. The purpose of Themify is to allow the developer to group views inside themes, having each theme its own folder. If you have experience with Yii framework theming, you will find this package usage very familiar.
A sample structure folder could be like this:
app/
├── Http
├── ...
├── themes
│ ├── admin
│ │ ├── category
│ │ ├── dashboard
│ │ ├── ...
│ └── default
│ ├── index.blade.php
│ ├── layouts
│ ├── post
│ └── ...
Themify expects you to store your themes in a given folder, which is app/themes by default. Then, each theme should have its own views inside its folder, just like it was a views folder.
Installation
- Use composer to install the package:
composer require nwidart/themify=*
- Add the ServiceProvider to your service provider list inside
app/config/app.php:
'providers' => array( ... 'Illuminate\View\ViewServiceProvider', 'Illuminate\Workbench\WorkbenchServiceProvider', 'Nwidart\Themify\ThemifyServiceProvider', ),
- Add the Facade to your aliases array inside
app/config/app.php:
'aliases' => array( ... 'URL' => 'Illuminate\Support\Facades\URL', 'Validator' => 'Illuminate\Support\Facades\Validator', 'View' => 'Illuminate\Support\Facades\View', 'Themify' => 'Nwidart\Themify\Facades\Themify', ),
-
Create your
themesdirectory inside your application. By default, Themify expects anapp/themesdirectory, but this can be modified in the package configuration. -
Publish package configuration with artisan:
php artisan vendor:publish
Then, modify settings as needed by editing config/themify.php.
Usage
First, you have to tell the package which theme you want to use. You have three different ways to do this, ordered by priority:
- Calling
Themify::set($theme). Beingthemethe name of the folder of the theme you want to use. - Defining a
public $themeproperty in your controller. - Using
Themify::defaults($theme), which is a shortcut to changing thethemify::default_themeproperty in package settings.
Once you have defined your theme, you can render your views using the View class in the traditional way. Themify will try to find the specified view inside the defined theme folder. If it doesn't find it, it will fallback to the default views folder (or whatever you have defined in your app/config/view.php).
View::render('foo', compact($bar));
Priorities
Each of the mentioned methods has an internal priority assigned:
- If the theme is explicitly set using
Themify::set($theme), the only way to override it is to useset()again. - If no calls to
set()are found, Themify will check for a$themeproperty in the current controller (if any). Note that this property should bepublic. This check is made through a simplebeforefilter that the ServiceProvider of the package adds to all routes.
<?php class MyAwesomeController extends BaseController { public $theme = 'bootstrap'; public function index() { return View::make('index'); } }
- If no
$themeproperty is found on the controller, or there is no controller for the current route, Themify will get the value inside it's configuration file. This value can be set either at runtime usingThemify::defaults($theme), or modifying thethemify::default_themeproperty inside theconfig.phpthat you published with artisan.
Theme assets
Themify expects you to have a folder inside your public directory (or the one that you have defined in your Laravel configuration) to store theme assets. By default, this folder is public/assets/themes, but it can be modified in the package configuration file.
Thus, this assets folder should contain one folder per theme. For example, if you are using a bootstrap theme, you should create public/assets/themes/bootstrap, and then create your stylesheets, javascripts and other assets there.
Helpers
Themify provides two convenient helpers for your views: theme_url() and theme_secure_url(), which will return the path to your current theme assets folder.
<link rel="stylesheet" type="text/css" href="{{ theme_url() }}/css/styles.css"> <script src="{{ theme_url() }}/js/main.min.js"></script>
Examples
Setting a theme for a group of routes
<?php Route::filter('admin.theme', function() { // We use default() so we can // override later if we want Themify::default('admin') }); Route::group(['prefix' => 'admin', 'before' => 'admin.theme'], function() { // All of these routes will use // 'admin' theme // Override this route with a // different theme Route::get('login', function() { Themify::set('basic'); }); });
Setting a theme for all controller actions
You can define your theme in a per controller basis, using a public $theme property inside your controllers:
<?php class FooController extends BaseController { public $theme = 'footheme'; public function someAction() { // For this one, use a different theme Themify::set('bartheme'); } }
nwidart/themify 适用场景与选型建议
nwidart/themify 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 83 次下载、GitHub Stars 达 4, 最近一次更新时间为 2015 年 02 月 10 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 nwidart/themify 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 nwidart/themify 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 83
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 15
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-02-10