pierresilva/laravel-themes
Composer 安装命令:
composer require pierresilva/laravel-themes
包简介
Laravel 5.3 Themes Support
README 文档
README
Laravel Themes gives the means to group together a set of views and assets for Laravel 5.3.
Quick Installation
Begin by installing the package through Composer.
composer require pierresilva/laravel-themes
Once this operation is complete, simply add both the service provider and facade classes to your project's config/app.php file:
Service Provider
pierresilva\Themes\ThemesServiceProvider::class,
Facade
'Theme' => pierresilva\Themes\Facades\Theme::class,
Publishing The Config File
php artisan vendor:publish --provider="pierresilva\Themes\ThemesServiceProvider"
This will copy the bundled config file to config/themes.php
Configuration Options
Default Active Theme
Define the default active theme.
'active' => 'default'
Folder Structure
Generating forlder structure from command line.
php artisan generate:theme themeslug
And fallow the instructions.
Manifest File
Each theme must come supplied with a manifest file (theme.json) stored at the root of the theme, which defines supplemental details about the theme.
{
"slug": "default",
"name": "Default",
"author": "John Doe",
"description": "This is an example theme.",
"version": "1.0"
}
Get Manifest Properties
echo Theme::getProperty('theme::property_key', 'default value if nothing is returned');
Set Manifest Properties
Theme::setProperty('theme::property_key', 'new value to be set');
Setting The Active Themes
Using The Config File
config/laravel-themes.php
... 'active' => 'foobar' ...
Setting During Run-Time
app/Http/Controllers/Controller.php
use Theme; ... public function __construct() { Theme::setActive('foobar'); } ...
Facade Reference
Theme::all()
Get all themes.
Returns
Collection
Example
$themes = Theme::all();
Theme::setActive($theme)
Sets the active theme that will be used to retrieve view files from.
Parameters
$theme (string) Theme slug. Required
Returns
null
Example
Theme::setActive('bootstrap-theme');
Theme::getActive()
Returns the currently active theme.
Returns
string
Example
$activeTheme = Theme::getActive();
Theme::view($view, $data)
Renders the defined view. This will first check if the currently active theme has the requested view file; if not, it will fallback to loading the view file from the default view directory supplied by Laravel.
Parameters
$view (string) Relative path to view file. Required $data (mixed) Any additional data you'd like to pass along to the view file to be displayed.
Returns
View
Example
$foo = 'bar'; return Theme::view('welcome', compact('foo'));
Theme::response($view, $data, $status, $headers)
Rendered the defined view in the same manner that Theme::view() does, but allows the means to set a custom status response and header for the rendered page.
Parameters
$view (string) Relative path to view file. Required $data (mixed) Any additional data you'd like to pass along to the view file to be displayed. $status (integer) HTTP status code. $header (array) HTTP headers.
Returns
Response
Example
$posts = Post::orderBy('published', 'desc')->get(); return Theme::response('blog.rss', compact('posts'), 200, [ 'Content-Type' => 'application/atom+xml; charset=UTF-8' ]);
Start building some awesome themes!
Let's say we have bootstrap theme in our application with the following structure:
public/
|-- themes/
|-- bootstrap/
|-- theme.json
|-- assets/
|-- css/
|-- bootstrap.css
|-- img/
|-- js/
|-- bootstrap.js
|-- jquery.js
|-- views/
|-- layout.blade.php
|-- auth/
|-- login.blade.php
First, we need theme.json manifest file.
{
"slug": "bootstrap",
"name": "Bootstrap",
"author": "Jhon Doe",
"description": "Bootstrap theme.",
"version": "1.0.0"
}
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Bootstrap Theme Sample</title> <!-- Bootstrap core CSS --> <link href="{{ Theme::asset('bootstrap::css/bootstrap.css') }}" rel="stylesheet"> </head> <body> <div class="container"> @yield('content') </div> <script src="{{ Theme::asset('bootstrap::js/jquery.js') }}"></script> <script src="{{ Theme::asset('bootstrap::js/bootstrap.js') }}"></script> </body> </html>
Please take note that we need to use Theme::asset() to load our theme asset files. The bootstrap is a theme slug defined in our theme.json file.
In our controller, load the view using the following code:
public function getLogin() { return Theme::view('auth.login'); }
Now, for our login.blade.php:
@extends('bootstrap::layout')
@section('content')
<h1>Log In</h1>
<form method="POST" action="/auth/login">
{!! csrf_field() !!}
<div>
Email
<input type="email" name="email" value="{{ old('email') }}">
</div>
<div>
Password
<input type="password" name="password" id="password">
</div>
<div>
<input type="checkbox" name="remember"> Remember Me
</div>
<div>
<button type="submit">Login</button>
</div>
</form>
@endsection
Note that we are using @extends('bootstrap::layout') in our login view, where bootstrap is a theme slug defined in our theme.json and layout is our layout file.
Author
License
The Laravel Themes is open-sourced software licensed under the MIT license.
pierresilva/laravel-themes 适用场景与选型建议
pierresilva/laravel-themes 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 187 次下载、GitHub Stars 达 2, 最近一次更新时间为 2017 年 01 月 18 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「themes」 「laravel」 「blade」 「pierresilva」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 pierresilva/laravel-themes 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 pierresilva/laravel-themes 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 pierresilva/laravel-themes 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Laravel Themes
WordPress mu-plugin to register the theme directory for the default WordPress themes.
This is twig version of Flow Theme for OXID eShop.
Test theme for Altis DXP, based on Automattic/_s starter theme.
This is a Smarty version of Admin Theme for OXID eShop.
Themes module of YajraCMS.
统计信息
- 总下载量: 187
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 16
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-01-18