buzz/laravel-theme

v2.4.3 2016-01-04 06:52 UTC

This package is auto-updated.

Last update: 2024-09-07 22:33:54 UTC


README

检测设备使用包 serbanghita/Mobile-Detect。如果您想简化操作,请使用版本 1。注意:v2.* 切换语言为越南语

内容

  1. 介绍
  2. 安装
  3. 配置
  4. 结构
  5. 用法

介绍

本包支持管理在单独文件夹下的视图文件和资产。兼容Laravel 5.*

安装

首次运行命令

composer require buzz/laravel-theme 2.*

然后打开 config/app.phpLaravelThemeServiceProvider 添加到 providers 数组中

'providers' => [
    //.....
    'Illuminate\Validation\ValidationServiceProvider',
    'Illuminate\View\ViewServiceProvider,
    //.....
    'Buzz\LaravelTheme\LaravelThemeServiceProvider',
],

添加 Theme 别名(当在主题配置中设置 auto_alias => false 时)

'aliases' => [
    //.....
    'Validator' => 'Illuminate\Support\Facades\Validator',
    'View'      => 'Illuminate\Support\Facades\View',
    //.....
    'Theme' =>  'Buzz\LaravelTheme\ThemeFacade',
],

配置

使用命令发布配置文件 config/theme.php

php artisan vendor:publish --provider="Buzz\LaravelTheme\LaravelThemeServiceProvider"

用法

结构

资产
├── public/
    └── themes/
        ├── theme_name/
        |   ├── js/
        |   ├── css/
        |
        └── another_theme_name/

视图
├── resources/
    └── themes/
        ├── theme_name/
        |   ├── index.blade.php
        |   ├── footer.blade.php
        |
        └── another_theme_name/

渲染视图

包不会改变您渲染视图的方式,您仍然使用laravel的默认方式,如 View::makeview(),更多详情请参阅 视图文档。如果视图和渲染视图在 resources/themes/theme-name 中不存在,它将渲染 resources/views 中的视图。

主题资产

在主题中链接资产时,请使用 themeAsset() 代替 asset(),例如

<link rel="stylesheet" href="{!! themeAsset('css/bootstrap.css') !!}">
//render <link rel="stylesheet" href="http://domain/themes/theme-name/css/bootstrap.css">

更改当前主题

您可以通过以下方式更改主题

app('theme')->set($themeName)

或使用函数助手

setTheme($themeName);//function helper

或使用外观

Theme::set($themeName);//use facade

支持方法

Theme::client();//return object of MobileDetect
Theme::pathTheme($name = null);//return path to current theme or name input
Theme::currentTheme();//return name of current theme
Theme::reset();//reset default theme
Theme::set();//set theme
Theme::allTheme($except = [], $config = true);//get list theme in folder themes
themeAsset($name = false);//link to asset current theme or by theme name
setTheme($name);// change theme by theme name

支持其他配置提供者

默认情况下,包使用laravel的 config 提供者,您可以通过编辑配置 'config_provider' => 'provider_name' 来更改到您想要的提供者

备注:对不起,我的英语不好。