jasco-b/theme

Laravel多主题库

1.2 2020-09-22 18:20 UTC

This package is auto-updated.

Last update: 2024-09-23 02:34:37 UTC


README

Laravel-Theme 是 Laravel 5+ 的主题管理工具,它是组织皮肤、布局和资源的最简单方式。

用法

主题提供了许多功能,帮助您开始使用 Laravel

安装

'providers' => [
	...
	 \JascoB\Theme\Providers\ThemeServiceProvider::class,

]

主题还包含一个门面,提供创建集合的静态语法。您可以在 config/app.php 文件的 aliases 键中注册门面。

'aliases' => [
	...
	'Theme'=> \JascoB\Theme\Facades\Theme::class,

]

使用 artisan CLI 发布配置。

php artisan vendor:publish --provider="JascoB\Theme\Providers\ThemeServiceProvider"

创建新主题

第一次需要使用 artisan 命令创建主题 "default" 结构

php artisan theme:create default

这将创建以下目录结构

├── public/
    └── themes/
	    └── default/
		    ├── assets
        	    └── config.json

要删除现有主题,使用以下命令

php artisan theme:delete default

要列出所有已安装的主题,使用以下命令

php artisan theme:list

您可以复制现有主题

php artisan theme:duplicate name new-theme

在不使用 CLI 的情况下从应用程序创建

Artisan::call('theme:create', ['name' => 'foo']);

基本用法

要从控制器显示视图

namespace App\Http\Controllers;

use Theme;

class HomeController extends Controller {

	public function getIndex()
	{
		return Theme::view('index');
	}
	...
}

您可以在路由中将其用作中间件

Route::get('/', function () {
    //
})->middleware('theme:yourtheme');

您可以手动设置主题

...		
Theme::set('themename');
        
return Theme::view('index');
...

检查主题是否存在。

Theme::has('themename');

每个主题都必须包含一个位于主题根目录的 config.json 清单文件,它定义了有关主题的补充信息。

{
    "name": "Default"
}

自定义辅助函数

@themeInclude 是用于包含补充视图的 blade 指令,例如

## insted of 
@include('someview', ['somedata'=>$var])

## use theme campatible
@themeInclude('someview', ['somedata'=>$var] )

@themeFirst 是代替 @includeFirst 的 blade 指令

## insted of 
@includeFirst(['someview','view-other'], ['somedata'=>$var] )

## use theme campatible
@themeFirst(['someview','view-other'], ['somedata'=>$var] )

包将根据配置文件 theme.php 中的指示将资源文件夹发布到公共文件夹
要获取当前主题的 URL,请使用 theme_uri() 函数

<link href="{{ theme_uri() }}/css/style.css" rel="stylesheet" />

<script src="{{ theme_uri() }}/js/script.js"></script>

<img src="{{ theme_uri() }}/image/img.png" />

请将所有资源放置在 assets 文件夹中,并正确更改 config/theme.php 文件

自定义主题模板

如果您想更改模板,可以使用

php artisan vendor:publish --provider="JascoB\Theme\Providers\ThemeServiceProvider" --tag="template"

它将在 resources/views/vendor/theme/template 上创建一个文件夹,您可以在那里创建模板,然后包将从那里复制模板

测试

要运行测试

php vendor/bin/phpunit tests