定制 pierresilva/laravel-themes 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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

Pierre Silva

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 我们能提供哪些服务?
定制开发 / 二次开发

基于 pierresilva/laravel-themes 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 187
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 16
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-01-18