Giter VIP home page Giter VIP logo

themevel's Introduction

Laravel-Themevel

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

When the download is complete, you have to call this package service in config/app.php config file. To do that, add this line in app.php in providers section

Shipu\Themevel\Providers\ThemevelServiceProvider::class,

To use facade you have to add this line in app.php in 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 theme exist or not

Theme::has(); // return bool

getThemeInfo

For getting theme exist or not

$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 asset you can use assets method

Theme::assets('your_asset_path'); // return string

It's Generate BASE_URL/theme_roots/your_active_theme_name/assets/your_asset_path

If your_asset_path 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

For using helper you can also get assets path:

themes('your_asset_path'); // return string

If You 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 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_themen_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 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.

use Shipu\Themevel\Contracts\ThemeContract;

private $theme;

public function __construct(ThemeContract $theme)
{
    $this->theme = $theme
}

Support for this project

Hey dude! Help me out for a couple of ๐Ÿป!

Beerpay Beerpay

themevel's People

Contributors

shipu avatar

Watchers

James Cloos avatar Md. Jahidul Islam avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.