madan2056 / yapptheme
支持Laravel 8/9主题,包括资产、主题扩展等。
dev-master
2023-01-11 04:13 UTC
Requires
- php: >=7.4
- friendsofphp/php-cs-fixer: ^3.13
This package is not auto-updated.
Last update: 2024-09-19 10:56:22 UTC
README
受 bigecko/laravel-theme 启发。主题存储在默认的laravel资源文件夹中
要求
此包需要 PHP 7.3 或更高版本 8.* 以及 Laravel 8 或 9。
目前仅支持与webpack结合使用的 laravel-mix
。
安装
您可以通过以下方式使用composer安装此包
composer require yaap/theme
或手动将行添加到 composer.json
{ "require": { "yaap/theme": "^4.0" } }
可选,使用artisan CLI发布配置(如果您想覆盖默认配置)。
php artisan vendor:publish --provider="YAAP\Theme\ThemeServiceProvider"
配置
包配置
return [ /* |-------------------------------------------------------------------------- | Path to directory with themes |-------------------------------------------------------------------------- | | The directory with your themes. | */ 'path' => base_path('themes'), /* |-------------------------------------------------------------------------- | Path to directory with assets build |-------------------------------------------------------------------------- | | The directory with assets build in public directory. | */ 'assets_path' => 'themes', /* |-------------------------------------------------------------------------- | A pieces of theme collections |-------------------------------------------------------------------------- | | Inside a theme path we need to set up directories to | keep "layouts", "assets" and "partials". | */ 'containerDir' => [ 'assets' => 'assets', 'lang' => 'lang', 'layout' => 'layouts', 'partial' => 'partials', 'view' => 'views', ], ];
主题配置
主题文件夹中的配置
return [ /* |-------------------------------------------------------------------------- | Theme name |-------------------------------------------------------------------------- | | Use in assets publishing etc. | */ 'name' => '%theme_name%', /* |-------------------------------------------------------------------------- | Inherit from another theme |-------------------------------------------------------------------------- | | Set up inherit from another if the file is not exists. | */ 'inherit' => null, ];
使用方法
使用artisan CLI创建主题
第一次您需要使用artisan命令创建主题 default
结构
php artisan theme:create default
为了将自定义规则添加到 webpack.mix.js
中,请添加 --with-mix
选项
php artisan theme:create default --with-mix
要删除现有主题,请使用以下命令
php artisan theme:destroy default
结构
以下是带有主题的项目文件夹结构示例
project-root
├── app/
<...>
├── public/
| ├── index.php
| └── themes/
| └── default/
| ├── js/
| | └── app.js
| ├── css/
| | └── styles.css
| └── images/
| └── icon.png
├── resources/
<...>
├── themes/
| ├── default/
| | ├── assets/
| | ├── lang/
| | ├── layouts/
| | ├── partials/
| | ├── views/
| | | └── hello.blade.php
| | └── config.php
| ├── admin/
| ├── views/
| ├── emails/
| | └── notify.blade.php
| └── hello.blade.php
初始化主题
Theme::init($name)
这将添加到视图查找路径
- themes/{$name}
- themes/{$name}/views
还将添加语言文件
- themes/{$name}/lang
制作视图
View::make('hello'); View::make('emails.notify');
资产
使用laravel mix进行资产。
在页眉中
<link rel="stylesheet" href="{{ mix('/themes/default/css/app.min.css') }}"/>
和页脚中
<script type="text/javascript" src="{{ mix('/themes/default/js/app.min.js') }}"></script>
Blade模板
@extends('layouts.master')
@include('partials.header')
@section('content')
<section id="main">
<h1>HOME</h1>
</section>
@stop
@include('partials.footer')
回退功能
您仍然可以使用存储在主题目录外的默认 View::make('emails.notify')
。
我可以雇佣你们吗?
是的!打招呼:hello@hexide-digital.com
我们很乐意与您合作!我们的其他 作品
关注我们
关注最新的Vuestic新闻!在 LinkedIn 或 Facebook 上关注我们
许可
MIT 许可证。