shipu/themevel
Composer 安装命令:
composer require shipu/themevel
包简介
Theme and asset management for laravel
README 文档
README
Themevel is a Laravel theme and asset management package. You can easily integrate this package with any Laravel based project.
Features
- Custom theme path
- Override theme
- Parent theme support
- Unlimited Parent view finding
- Asset Finding
- Theme translator support
- Multiple theme config extension
- Multiple theme changelog extension
- Artisan console commands
- Theme enable only Specific route via middleware
- Almost everything customizable
- Also Laravel 5.5 to Laravel 10 Supported
Installation
Themevel is a Laravel package so you can install it via Composer. Run this command in your terminal from your project directory:
composer require shipu/themevel
Wait for a while, Composer will automatically install Themevel in your project.
Configuration
Below Laravel 5.5 you have to call this package service in config/app.php config file. To do that, add this line in app.php in providers array:
Shipu\Themevel\Providers\ThemevelServiceProvider::class,
Below Laravel 5.5 version to use facade you have to add this line in app.php to the aliases array:
'Theme' => Shipu\Themevel\Facades\Theme::class,
Now run this command in your terminal to publish this package resources:
php artisan vendor:publish --provider="Shipu\Themevel\Providers\ThemevelServiceProvider"
Artisan Command
Run this command in your terminal from your project directory.
Create a theme directory:
php artisan theme:create your_theme_name What is theme title?: > What is theme description? []: > What is theme author name? []: > What is theme version? []: > Any parent theme? (yes/no) [no]: > y What is parent theme name?: >
List of all themes:
php artisan theme:list +----------+--------------+---------+----------+ | Name | Author | Version | Parent | +----------+--------------+---------+----------+ | themeone | Shipu Ahamed | 1.1.0 | | | themetwo | Shipu Ahamed | 1.0.0 | themeone | +----------+--------------+---------+----------+
Example folder structure:
- app/
- ..
- ..
- Themes/
- themeone/
- assets
- css
- app.css
- img
- js
- lang
- en
-content.php
- views/
- layouts
- master.blade.php
- welcome.blade.php
- changelog.yml
- theme.json
- themetwo/
You can change theme.json and changelog.yml name from config/theme.php
// .. 'config' => [ 'name' => 'theme.json', 'changelog' => 'changelog.yml' ], // ..
json, yml, yaml, php, ini, xml extension supported.
For example:
// .. 'config' => [ 'name' => 'theme.json', 'changelog' => 'changelog.json' ], // ..
Then run theme:create command which describe above.
Now Please see the API List Doc.
View Finding Flow:
Suppose you want find welcome.blade.php
- At first check your active theme
- If `welcome.blade.php not found in active theme then search parent recursively
- If `welcome.blade.php not found in parents theme then search laravel default view folder resources/views
API List
set
For switching current theme you can use set method.
Theme::set('theme-name');
get
For getting current theme details you can use get method:
Theme::get(); // return Array
You can also get particular theme details:
Theme::get('theme-name'); // return Array
Theme::get('theme-name', true); // return Collection
current
Retrieve current theme's name:
Theme::current(); // return string
all
Retrieve all theme information:
Theme::all(); // return Array
has
For getting whether the theme exists or not:
Theme::has(); // return bool
getThemeInfo
For info about the specified theme:
$themeInfo = Theme::getThemeInfo('theme-name'); // return Collection $themeName = $themeInfo->get('name'); // or $themeName = $themeInfo['name'];
Also fallback support:
$themeInfo = Theme::getThemeInfo('theme-name'); // return Collection $themeName = $themeInfo->get('changelog.versions'); // or $themeName = $themeInfo['changelog.versions']; // or you can also call like as multi dimension $themeName = $themeInfo['changelog']['versions'];
assets
For binding theme assets you can use the assets method:
Theme::assets('your_asset_path'); // return string
It's generated at BASE_URL/theme_roots/your_active_theme_name/assets/your_asset_path
If your_asset_path does not exist then it's find to active theme immediate parent assets folder. Look like BASE_URL/theme_roots/your_active_theme_parent_name/assets/your_asset_path
When using helper you can also get assets path:
themes('your_asset_path'); // return string
If you want to bind specific theme assets:
Theme::assets('your_theme_name:your_asset_path'); // return string // or themes('your_theme_name:your_asset_path'); // return string
Suppose you want to bind app.css in your blade. Then below code can be applicable:
<link rel="stylesheet" href="{{ themes('app.css') }}">
Specific theme assets:
<link rel="stylesheet" href="{{ themes('your_theme_name:app.css') }}">
lang
The lang method translates the given language line using your current theme localization files:
echo Theme::lang('content.title'); // return string // or echo lang('content.title'); // return string
also support
echo Theme::lang('content.title', [your replace array], 'your desire locale'); // return string // or echo lang('content.title', [your replace array], 'your desire locale'); // return string
If you want to bind specific theme assets:
echo Theme::lang('your_theme_name::your_asset_path'); // return string // or echo lang('your_theme_name::your_asset_path'); // return string
How to use in Route
Route::get('/', function () { Theme::set('your_theme_name'); return view('welcome'); });
This will firstly check if there is a welcome.blade.php in current theme directory. If none is found then it checks parent theme, and finally falls back to default Laravel views location.
If you want to specific theme view:
Route::get('/', function () { Theme::set('your_theme_name'); return view('your_theme_name::welcome'); });
Set theme using route middleware
A helper middleware is included out of the box if you want to define a theme per route. To use it:
First register it in app\Http\Kernel.php:
protected $routeMiddleware = [ // ... 'theme' => \Shipu\Themevel\Middleware\RouteMiddleware::class, ];
Now you can apply the middleware to a route or route-group. Eg:
Route::group(['prefix' => 'admin', 'middleware'=>'theme:Your_theme_name'], function() { // ... Add your routes here // The Your_theme_name will be applied. });
Set theme using web middleware
A helper middleware is included out of the box if you want to define a theme per route. To use it:
First register it in app\Http\Kernel.php:
protected $middlewareGroups = [ 'web' => [ // ... \Shipu\Themevel\Middleware\WebMiddleware::class, ], // ... ];
Theme set from config/theme.php .
Then in your controller you can call your view as you would normally do:
return view('home'); // This will load the home.blade.php from the the folder you set in your `config/theme.php`
Dependency Injection
You can also inject theme instance using ThemeContract, eg:
use Shipu\Themevel\Contracts\ThemeContract; private $theme; public function __construct(ThemeContract $theme) { $this->theme = $theme }
Troubleshooting
Clear config after runing vendor publish (see Config section) to save issues related to config caching by running:
php artisan config:cache
php artisan config:clear
Credits
Support for this project
Hey dude! Help me out for a couple of 🍻!
shipu/themevel 适用场景与选型建议
shipu/themevel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 32.8k 次下载、GitHub Stars 达 346, 最近一次更新时间为 2017 年 05 月 17 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「asset」 「theme」 「management」 「laravel」 「multi」 「lumen」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 shipu/themevel 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 shipu/themevel 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 shipu/themevel 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Asset for Bulma Free for YiiFramework v.3.0.
A Bootstrap 4.x base theme for SilverStripe
A Silverstripe module to allow you to log into any of your Silverstripe sites from one place.
Lucency Theme
Task system for APPUI
Symfony Utils Bundle
统计信息
- 总下载量: 32.8k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 348
- 点击次数: 11
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: CC-BY-3.0
- 更新时间: 2017-05-17