Theme and asset management for laravel

Overview

Laravel-Themevel

Latest Stable Version Latest Stable Version Latest Unstable Version License

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 7.0+, 8.0+ Support

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 🍻 !

Beerpay Beerpay

Comments
  • What about template error pages?

    What about template error pages?

    We can override laravel error pages with putting error files(404.blade.php, 500.blade.php etc.) into "resources/views/errors" folder.

    I put error pages in my template folder(etc themes/dashboard/views/errors/404.blade.php) but it didn't work.

    How can override error pages in template views?

    I know its about exception handling, we must add template path in view config paths.

    But we need proper implementation.

    image

    opened by enverarslan 4
  • I am interested in using the themevel...

    I am interested in using the themevel...

    I am interested in creating a interface like wordpress for choosing the theme can i use this package ... I am little confused so writing this message..

    please guide me

    opened by raghavan2004 3
  • Make this less opinionated

    Make this less opinionated

    Although I really like what you have done here I think it could be a little less opinionated.

    For example it's extensive use of ucfirst() could be better. It shouldn't decide for us how to case our description or author. Defaulting the author to your own name isn't something I would personally do either.

    The same can be said about the symlink. This defaults to 'Themes'. This is personal preference but I would probably use a different name for this. It would be great if we could configure the name of the symlink instead.

    Happy to help with PR's of course.

    opened by ju5t 3
  • Problem when trying to create a new Theme

    Problem when trying to create a new Theme

    I'm trying to execute the command php artisan theme:create your_theme_name but I received an error mkdir() permission denied so I have tried to run the command with sudo and this happens:

    image

    opened by surebro00 3
  • Is it support layout switching.

    Is it support layout switching.

    Suppose, one theme has 2/3 deferent layouts (app_ayout.blead.php, profile_layout_blade.php etc). And want to switch layout on runtime. Is there anything there. Just similar like CakePHP (https://book.cakephp.org/3.0/en/views.html)

    question 
    opened by sohelrana820 3
  • Add BeforeThemeLoaded and AfterThemeLoaded Events

    Add BeforeThemeLoaded and AfterThemeLoaded Events

    Added events to respond to Theme loading. The BeforeThemeLoaded event will not allow a theme to be loaded if it returns false.

    The event is also passed the $level so the user can tell if it is a parent/grandparent, etc.

    opened by dariusj18 2
  • Theme trying to load when null or blanks

    Theme trying to load when null or blanks

    If the active theme is configured as null or blank there doesn't seem to be any reason a theme should attempt to be loaded.

    Theme [ ] not found! Maybe you're missing a theme.json file.

    opened by dariusj18 2
  • Wrong theme url

    Wrong theme url

    Hi, Using: <link rel="stylesheet" href="{{ themes('css/app.css') }}">

    in a view it creates this url: http://www.somedomain.com/<theme_name>/assets/css/app.css but it should be http://www.somedomain.com/themes/<theme_name>/assets/css/app.css that corresponds to the symlink created in the public folder. Is this a bug or am I doing something wrong?

    Thanks

    bug 
    opened by eonlab 2
  • Livewire polling issue

    Livewire polling issue

    Hello,

    The package works fine without polling but when I use the wire:poll feature, I get InvalidArgumentException.

    InvalidArgumentException View [livewire.admin.deploy-soft] not found.

    opened by vixocomtr 1
  • change the symlink creation condition

    change the symlink creation condition

    I noticed laravel's File:exists() wasn't working correctly with symlinks, I changed it with pure php's is_link() function and recombined your condition for more brevity. Please merge it if you agree with this. Thank you!

    opened by tmtung144 1
  • Accessing particular theme assets in active theme

    Accessing particular theme assets in active theme

    i am trying to access another theme assets in active theme .But i didnt found any existing method . I have tried

    Theme::assets('anotherTheme:img/a.jpg')

    but return active path like

    http://localhost/Themes/activeThemeName/assets/anotherTheme/assets/img/a.jpg

    Using "laravel/framework": "^8.12", "shipu/themevel": "^2.2" ,Linux machine

    thanks for this library

    opened by codetestmg 1
  • "Cannot create a file when that file already exists." message when using php artisan

    I found this rather harmless effect after creating themes. Whenever I'm using any php artisan command like php artisan --version I keep getting a message "Cannot create a file when that file already exists." and then the execution happens normally.

    I'm using Laravel 8.83.20.

    I suspect it keeps trying to generate symbolic link in the public folder, as simply putting a Themes folder and running the php artisan --version command generated the symbolic link. Hope you look into this and sort it out.

    opened by samik-os 0
Releases(v3.0.3)
Owner
Shipu Ahamed
General Manager, Lead Backend Engineer at Robi 10 Minute School
Shipu Ahamed
Theme and asset management for laravel

Laravel-Themevel Themevel is a Laravel theme and asset management package. You can easily integrate this package with any Laravel based project. Featu

Shipu Ahamed 339 Dec 23, 2022
Textpattern-default-theme - Textpattern CMS default theme.

Textpattern CMS default theme This project is the source for the default theme that ships as standard with Textpattern CMS. It is intended as a starti

Textpattern CMS 61 Nov 21, 2022
Textpattern-jquery-ui-theme - The jQuery UI theme used within the Textpattern CMS admin-side.

Textpattern jQuery UI theme The jQuery UI theme used within the Textpattern CMS admin-side. Supported web browsers Chrome, Edge, Firefox, Safari and O

Textpattern CMS 12 Jan 10, 2022
laravel - Potion is a pure PHP asset manager for Laravel 5 based off of Assetic.

laravel-potion Potion is a pure PHP asset manager for Laravel based off of Assetic. Description Laravel 5 comes with a great asset manager called Elix

Matthew R. Miller 61 Mar 1, 2022
A Laravel package to speed up deployment by skipping asset compilation whenever possible.

Airdrop for Laravel Read the full docs at hammerstone.dev/airdrop/docs. Hammerstone Airdrop for Laravel is a package that speeds up your deploys by sk

Hammerstone 160 Nov 24, 2022
🧾 Online test site with the human sciences theme. Using: HTML5, CSS3, Js., PHP7 and MySQL. 🚀

form-ciencias-humanas ?? Technologies Lunacy HTML5 CSS3 PHP7 MYSQL Animate.css Illustrations from icons8: Earth care from Anna Antipina Earth and Moon

Vinícius 1 Jan 9, 2022
Multi theme support for Laravel application

Multi theme support for Laravel application This Laravel package adds multi-theme support to your application. It also provides a simple authenticatio

QiroLab 287 Dec 29, 2022
Simple Laravel 5+ (5.4) Theme Switcher with Middleware!

Laravel Theme The simpliest of theme switching for Laravel 5 Installation Usage Installation Laravel 5.1+ Install Laravel Theme manager: composer requ

null 11 Aug 30, 2020
Support multi theme for Laravel application

Very short description of the package This is where your description should go. Try and limit it to a paragraph or two, and maybe throw in a mention o

Ephraïm SEDDOR 1 Dec 1, 2021
Ten Theme From Youtube Videos

Webverse_ten This is the main branch of the Ten Theme from Youtube Videos, to view the progress of a specific video switch to the corresponding branch

Webverse 10 Dec 5, 2022
Admin Theme based on the AdminLTE Template for easy integration into symfony

Admin Theme based on the AdminLTE Template for easy integration into symfony

Marc Bach 281 Aug 30, 2022
Bootstrap Theme Generator inside of a Wordpress-Settings-Page. Includes live compilation of SCSS!

Bootstrap-Theme-Generator Bootstrap Theme Generator enables you to choose which components of Bootstrap you want to load. It also gives you the possib

null 3 Aug 15, 2022
Simple address and contact management for Laravel with automatically geocoding to add longitude and latitude

Laravel Addresses Simple address and contact management for Laravel with automatically geocoding to add longitude and latitude. Installation Require t

Chantouch Sek 2 Apr 4, 2022
GitScrum is a Project Management Tool, developed to help entrepreneurs, freelancers, managers, and teams Skyrocket their Productivity with the Agile methodology and Gamification.

What is GitScrum? GitScrum is a Project Management Tool, developed to help entrepreneurs, freelancers, managers, and teams Skyrocket their Productivit

GitScrum 2.8k Dec 29, 2022
Manage your staff from one place. Featuring Staff leave management 🏖, payslips 💵 generation & emailing, messaging 📨and more 🛠! Built with ❤️ with Laravel

Staff Management System This little buddy can help you manage your staff database! Built with ?? with Laravel #FEATURES 1 Staff management/ database S

Ezekiel Oladejo 45 Jan 3, 2023
Attendize is an open-source ticketing and event management application built using the Laravel PHP framework

Attendize is an open-source ticketing and event management application built using the Laravel PHP framework. Attendize allows event organisers to sel

Attendize 3.6k Dec 27, 2022
Admin user, role and permission management for Laravel Filament

Filament Access Control Opinionated setup for managing admin users, roles and permissions within Laravel Filament Features Separate database table for

Elisha Witte 69 Jan 4, 2023
Laravel Users | A Laravel Users CRUD Management Package

A Users Management Package that includes all necessary routes, views, models, and controllers for a user management dashboard and associated pages for managing Laravels built in user scaffolding. Built for Laravel 5.2, 5.3, 5.4, 5.5, 5.6, 5.7, 5.8, 6.0, 7.0 and 8.0.

Jeremy Kenedy 393 Nov 28, 2022
Packagit is amazing laravel modules management, you could manage huge project with many separate laravel modules.

Packagit is amazing laravel modules management, you could manage huge project with many separate laravel modules.

null 364 Dec 12, 2022