Theme management for laravel 5

v1.2 2018-05-06 07:42 UTC

This package is not auto-updated.

Last update: 2020-07-03 16:31:48 UTC


README

This is a theme management package for Laravel 5. You can easily integrate this package with any Laravel based project.

Features

  • Custom theme location
  • Ceparation frontend & backend
  • Unlimited Parent view finding
  • Multiple theme config extension
  • Multiple theme changelog extension
  • Artisan console commands
  • Translate

Installation

Install it via Composer. Run this command in your terminal from your project directory:

composer require vdhoangson/theme

Wait for a while, Composer will automatically install in your project.

Configuration

Call this package service in config/app.php config file. To do that, add this line in app.php in providers array:

vdhoangson\Theme\ThemeServiceProvider::class,

Now run this command in your terminal to publish this package resources:

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

Artisan Command

Run this command in your terminal from your project directory.

Create a theme directory:

php artisan theme:create place theme_name

place : frontend or backend

theme_name : Theme Name

 What is theme description? []:
 > 

 What is theme author name? []:
 >  

 What is theme version? []:
 > 

List of all themes:

php artisan theme:list

+---------+---------+------------+---------+
| Place   | Name    | Author     | Version |
+---------+---------+------------+---------+
| backend | default | vdhoangson | 1.0     |
+---------+---------+------------+---------+

Example folder structure:

- app/
- ..
- ..
- public/
    - themes/
        - default/
            - assets
                - css
                - img
                - js
            - views/
                - layouts
            - changelog.json        
            - theme.json

You can change theme.json and changelog.json name from config/theme.php

// ..
'config' => [
    'name' => 'theme.json',
    'changelog' => 'changelog.json'
],
// ..

Set theme using middleware

Use VSThemeFront for Frontend

Route::group(['prefix' => 'frontend', 'middleware'=>'VSThemeFront'], function() {
    // Theme will be applied.
});

Use VSThemeBack for Backend

Route::group(['prefix' => 'backend', 'middleware'=>'VSThemeBack'], function() {
    // Theme will be applied.
});

API List

setTheme

For switching current theme you can use setTheme method.

Theme::setTheme('theme-name');

getTheme

For getting current theme details you can use getTheme method:

Theme::getTheme(); // return Array

You can also get particular theme details:

Theme::getTheme('theme-name'); // return Array
Theme::getTheme('theme-name', true); // return Collection

currentTheme

Retrieve current theme's name:

Theme::currentTheme(); // return string

all

Retrieve all theme information:

Theme::all(); // return Array

exists

For getting whether the theme exists or not:

Theme::exists(); // return bool

themeInfo

For info about the specified theme:

$themeInfo = Theme::themeInfo('theme-name'); // return Collection

$themeName = $themeInfo->get('name');
// or
$themeName = $themeInfo['name'];

Also fallback support:

$themeInfo = Theme::themeInfo('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('asset_path'); // return string

When using helper you can also get assets path:

vassets('asset_path'); // return string

Add asset to html:

<link rel="stylesheet" href="{{ vassets('style.css') }}">

vtrans

You can translate language by vtrans method:

When using helper you can also get assets path:

vtrans('your_file.your_key'); // return string

Credits