PHP Classes

Themevel: Manage themes and assets for Laravel applications

Recommend this page to a friend!
  Info   Documentation   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 44 All time: 10,814 This week: 488Up
Version License PHP version Categories
themevel 1.3The PHP License5HTML, PHP 5, Libraries, Templates, Co...
Description 

Author

This package can manage themes and assets for Laravel applications.

It can generate theme asset files from configuration like CSS, templates and application translation to different languages.

The package can also load theme files at runtime to retrieve asset values like CSS file paths and localized text strings.

Themes can also be set using route middleware or dependency injection.

Picture of Shipu Ahamed
  Performance   Level  
Name: Shipu Ahamed <contact>
Classes: 1 package by
Country: Bangladesh Bangladesh
Age: 34
All time rank: 450152 in Bangladesh Bangladesh
Week rank: 197 Up4 in Bangladesh Bangladesh Up

Documentation

Laravel-Themevel

Latest Stable Version Latest Stable Version Latest Unstable Version License

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

Features

  • Custom theme location
  • Parent theme support
  • Unlimited Parent view finding
  • Asset Finding
  • Theme translator support
  • Multiple theme config extension
  • Multiple theme changelog extension
  • Artisan console commands

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

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.

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

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 .

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
}

Credits

Support for this project

Hey dude! Help me out for a couple of :beers:!

Beerpay Beerpay


  Files folder image Files (33)  
File Role Description
Files folder image.github (1 file)
Files folder imageconfig (1 file)
Files folder imagesrc (8 directories)
Files folder imagetests (2 files)
Accessible without login Plain text file .travis.yml Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE.md Lic. License text
Accessible without login Plain text file phpunit.xml Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files (33)  /  .github  
File Role Description
  Accessible without login Plain text file FUNDING.yml Data Auxiliary data

  Files folder image Files (33)  /  config  
File Role Description
  Accessible without login Plain text file theme.php Conf. Configuration script

  Files folder image Files (33)  /  src  
File Role Description
Files folder imageConsole (2 files, 1 directory)
Files folder imageContracts (1 file)
Files folder imageExceptions (1 file)
Files folder imageFacades (1 file)
Files folder imageHelpers (1 file)
Files folder imageManagers (1 file)
Files folder imageMiddleware (2 files)
Files folder imageProviders (1 file)

  Files folder image Files (33)  /  src  /  Console  
File Role Description
Files folder imagestubs (14 files)
  Plain text file ThemeGeneratorCommand.php Class Class source
  Plain text file ThemeListCommand.php Class Class source

  Files folder image Files (33)  /  src  /  Console  /  stubs  
File Role Description
  Accessible without login Plain text file changelogjson.stub Data Auxiliary data
  Accessible without login Plain text file changelogphp.stub Data Auxiliary data
  Accessible without login Plain text file changelogyaml.stub Data Auxiliary data
  Accessible without login Plain text file changelogyml.stub Data Auxiliary data
  Accessible without login Plain text file css.stub Data Auxiliary data
  Accessible without login Plain text file ini.stub Data Auxiliary data
  Accessible without login Plain text file json.stub Data Auxiliary data
  Accessible without login Plain text file lang.stub Data Auxiliary data
  Accessible without login Plain text file layout.stub Data Auxiliary data
  Accessible without login Plain text file page.stub Data Auxiliary data
  Accessible without login Plain text file php.stub Data Auxiliary data
  Accessible without login Plain text file xml.stub Data Auxiliary data
  Accessible without login Plain text file yaml.stub Data Auxiliary data
  Accessible without login Plain text file yml.stub Data Auxiliary data

  Files folder image Files (33)  /  src  /  Contracts  
File Role Description
  Plain text file ThemeContract.php Class Class source

  Files folder image Files (33)  /  src  /  Exceptions  
File Role Description
  Plain text file ThemeNotFoundException.php Class Class source

  Files folder image Files (33)  /  src  /  Facades  
File Role Description
  Plain text file Theme.php Class Class source

  Files folder image Files (33)  /  src  /  Helpers  
File Role Description
  Accessible without login Plain text file helpers.php Aux. Auxiliary script

  Files folder image Files (33)  /  src  /  Managers  
File Role Description
  Plain text file Theme.php Class Class source

  Files folder image Files (33)  /  src  /  Middleware  
File Role Description
  Plain text file RouteMiddleware.php Class Class source
  Plain text file WebMiddleware.php Class Class source

  Files folder image Files (33)  /  src  /  Providers  
File Role Description
  Plain text file ThemevelServiceProvider.php Class Class source

  Files folder image Files (33)  /  tests  
File Role Description
  Plain text file TestCase.php Class Class source
  Plain text file ThemeTest.php Class Class source

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:44
This week:0
All time:10,814
This week:488Up