2017 © Pedro Pelรกez
 

library theme

Theme support for Laravel 4/5 with assets, theme extends etc.

image

yaap/theme

Theme support for Laravel 4/5 with assets, theme extends etc.

  • Saturday, July 22, 2017
  • by yaapis
  • Repository
  • 4 Watchers
  • 81 Stars
  • 12,425 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 15 Forks
  • 1 Open issues
  • 19 Versions
  • 5 % Grown

The README.md

Theme support for Laravel

Inspired by bigecko/laravel-theme. Themes are stored inside default laravel's resources folder, (*1)

Introduction

This package provides a simple way to manage themes in Laravel applications., (*2)

For example, you can develop multiple themes for your application and easily switch between themes for different purposes., (*3)

Requirements

This version requires PHP 8.1 and supports Laravel 10-11., (*4)

This package also provides support for Laravel Mix and Vite configurations., (*5)

Themes L5.5 L5.6 L5.7 L5.8 L6 L7 L8 L9 L10 L11
2.4 :white_check_mark: :white_check_mark: :white_check_mark: :white_check_mark: :x: :x: :x: :x: :x: :x:
3.0 :x: :x: :x: :x: :white_check_mark: :x: :x: :x: :x: :x:
4.1 :x: :x: :x: :x: :x: :x: :white_check_mark: :white_check_mark: :white_check_mark: :x:
5.0 :x: :x: :x: :x: :x: :x: :x: :x: :white_check_mark: :x:
5.1 :x: :x: :x: :x: :x: :x: :x: :x: :white_check_mark: :white_check_mark:

Installation

To get the latest version, simply require the project using Composer:, (*6)

composer require "yaap/theme:^5.0"

or manually add line to composer.json, (*7)

{
    "require": {
        "yaap/theme": "^5.0"
    }
}

Optionally, publish config using artisan CLI (if you want to overwrite default config)., (*8)

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

Configuration

Package config

Config in config/theme.php file., (*9)

return [

    /*
    |--------------------------------------------------------------------------
    | Path to directory with themes
    |--------------------------------------------------------------------------
    |
    | The directory with your themes.
    |
    */

    'path' => base_path('themes'),

    /*
    |--------------------------------------------------------------------------
    | Path to directory with assets build
    |--------------------------------------------------------------------------
    |
    | The directory with assets build in public directory.
    |
    */

    'assets_path' => 'themes',

    /*
    |--------------------------------------------------------------------------
    | A pieces of theme collections
    |--------------------------------------------------------------------------
    |
    | Inside a theme path we need to set up directories to
    | keep "layouts", "assets" and "partials".
    |
    */

    'containerDir' => [
        'assets' => 'assets',
        'lang' => 'lang',
        'layout' => 'views/layouts',
        'partial' => 'views/partials',
        'view' => 'views',
    ],
];

Theme config

Config in theme folder. Placeholder %theme_name% will be replaced with theme name on creation., (*10)

return [

    /*
    |--------------------------------------------------------------------------
    | Theme name
    |--------------------------------------------------------------------------
    |
    | Use in assets publishing etc.
    |
    */

    'name' => '%theme_name%',

    /*
    |--------------------------------------------------------------------------
    | Inherit from another theme
    |--------------------------------------------------------------------------
    |
    | Set up inherit from another if the file is not exists.
    |
    */

    'inherit' => null,

];

Usage

Create theme with artisan CLI

Create command

The first time you have to create theme default structure, using the artisan command:, (*11)

php artisan theme:create default

By default, it will use vite as assets builder. If you want to use laravel mix instead, use the command:, (*12)

or with laravel mix:, (*13)

php artisan theme:create default mix

Destroy command

To delete an existing theme, use the command:, (*14)

php artisan theme:destroy default

Structure

Here is an example of the folder structure of project with theme, (*15)

project-root
โ”œโ”€โ”€ app/
<...>
โ”œโ”€โ”€ public/
|   โ”œโ”€โ”€ index.php
|   โ””โ”€โ”€ themes/
|       โ””โ”€โ”€ default/
|           โ”œโ”€โ”€ js/
|           |   โ””โ”€โ”€ app.js
|           โ”œโ”€โ”€ css/
|           |   โ””โ”€โ”€ styles.css
|           โ””โ”€โ”€ images/
|               โ””โ”€โ”€ icon.png
โ”œโ”€โ”€ resources/
<...>
โ”œโ”€โ”€ themes/
|   โ”œโ”€โ”€ default/
|   |   โ”œโ”€โ”€ assets/        
|   |   โ”œโ”€โ”€ lang/        
|   |   โ”œโ”€โ”€ views/
|   |   |   โ”œโ”€โ”€ layouts/
|   |   |   โ”œโ”€โ”€ partials/
|   |   |   โ””โ”€โ”€ hello.blade.php
|   |   โ””โ”€โ”€ config.php
|   โ”œโ”€โ”€ admin/
|   โ”œโ”€โ”€ views/
|       โ”œโ”€โ”€ emails/
|       |   โ””โ”€โ”€ notify.blade.php
|       โ””โ”€โ”€ hello.blade.php

Init theme

To init and use theme in your application, add the following code to any boot method in application service provider (e.g. AppServiceProvider):, (*16)

use YAAP\Theme\Facades\ThemeLoader;

class AppServiceProvider extends ServiceProvider
{
    public function boot()
    {
        ThemeLoader::init('default');
    }
}

This will add to views find path:, (*17)

  • themes/{$name}/views

Lang files will be added as well:, (*18)

  • themes/{$name}/lang

Making view

Laravel: Creating & Rendering Views, (*19)

View::make('hello');
View::make('emails.notify');

// or

view('hello');
view('emails.notify');

Assets

Vite

If you use Vite, ensure vite.config.js have specified the input path for theme, (*20)

import {defineConfig} from 'vite';
import laravel from 'laravel-vite-plugin';

export default defineConfig({
    plugins: [
        laravel({
            input: [
                'themes/default/assets/js/app.js', // for default theme
                // ...
            ],
            refresh: true,
        }),
    ],
});

Because app.js includes app.scss you can use the following code to include assets in your views:, (*21)

<head>
    <!--...-->
    @vite([
        'themes/default/assets/js/app.js',
    ])
</head>

Laravel Mix

If you use Laravel Mix, ensure webpack.mix.js have specified mix configuration for theme, (*22)

const mix = require('laravel-mix');

mix.disableNotifications();
mix.browserSync({
    open: true,
    proxy: 'localhost:8000',
    files: [
        'app/**/*',
        'routes/**/*', 
        'themes/**/*', // manually add this line
    ]
});

// other configutraions...

// mix for default theme
mix.copyDirectory('themes/default/assets/img', 'public/themes/default/img');
mix.copyDirectory('themes/default/assets/fonts', 'public/themes/default/fonts');
// js
mix.js(['themes/default/assets/js/app.js'], 'public/themes/default/js/app.min.js')
// sass
mix.sass('themes/default/assets/sass/app.scss', 'public/themes/default/css/app.min.css')

Then you can use the following code to include assets in your views:, (*23)

in the <head> tag, (*24)

<head>
    <!--...-->
    <link rel="stylesheet" href="{{ mix('/themes/default/css/app.min.css') }}"/>
</head>

and before </body> tag, (*25)

<body>
    <!--...-->
    <script type="text/javascript" src="{{ mix('/themes/default/js/app.min.js') }}"></script>
</body>

To use images, you can use the following code:, (*26)

<img src="{{ mix('themes/default/img/icon.png') }}" alt="icon">

Building layouts

Layouts using Components

Laravel: Blade Components, (*27)

Layouts using template inheritance

To build layouts we use template inheritance. You can use @extends directive to specify a parent layout., (*28)

@extends('layouts.master')

@include('partials.header')

@section('content')
    <section id="main">
        <h1>HOME</h1>
    </section>
@stop

@include('partials.footer')

Fallback capability

You still able to use default View::make('emails.notify') which is stored outside the themes directory., (*29)

Can I hire you guys?

Yes! Say hi: hello@hexide-digital.com, (*30)

We will be happy to work with you! Other work weโ€™ve done, (*31)

Follow us

Stay up to date with the latest news! Follow us on LinkedIn or Facebook, (*32)

License

MIT license., (*33)

The Versions

22/07 2017

dev-master

9999999-dev

Theme support for Laravel 4/5 with assets, theme extends etc.

  Sources   Download

MIT

The Requires

 

by Biluk Andrey

laravel asset theme layout

22/07 2017

2.4.0

2.4.0.0

Theme support for Laravel 4/5 with assets, theme extends etc.

  Sources   Download

MIT

The Requires

 

by Biluk Andrey

laravel asset theme layout

15/02 2017

2.3.0

2.3.0.0

Theme support for Laravel 4/5 with assets, theme extends etc.

  Sources   Download

MIT

The Requires

 

by Biluk Andrey

laravel asset theme layout

06/01 2016

2.2.0

2.2.0.0

  Sources   Download

MIT

The Requires

 

by Biluk Andrey

21/09 2015

v2.1.1

2.1.1.0

  Sources   Download

MIT

The Requires

 

by Biluk Andrey

26/06 2015

2.1

2.1.0.0

  Sources   Download

MIT

The Requires

 

by Biluk Andrey

24/03 2015

2.0

2.0.0.0

  Sources   Download

MIT

The Requires

 

by Biluk Andrey

24/03 2015

1.0.x-dev

1.0.9999999.9999999-dev

  Sources   Download

MIT

The Requires

 

by Biluk Andrey

30/09 2014

dev-develop

dev-develop

  Sources   Download

MIT

The Requires

 

by Biluk Andrey

22/06 2014

1.2.6

1.2.6.0

  Sources   Download

MIT

The Requires

 

by Biluk Andrey

22/06 2014

1.2.5

1.2.5.0

  Sources   Download

MIT

The Requires

 

by Biluk Andrey

26/05 2014

1.2.4

1.2.4.0

  Sources   Download

MIT

The Requires

 

by Biluk Andrey

25/05 2014

1.2.3

1.2.3.0

  Sources   Download

MIT

The Requires

 

by Biluk Andrey

25/05 2014

1.2.2

1.2.2.0

  Sources   Download

The Requires

 

by Biluk Andrey

25/05 2014

1.2.1

1.2.1.0

  Sources   Download

The Requires

 

by Biluk Andrey

25/05 2014

1.2.0

1.2.0.0

  Sources   Download

The Requires

 

by Biluk Andrey

24/05 2014

1.1.1

1.1.1.0

  Sources   Download

The Requires

 

by Biluk Andrey

24/05 2014

1.1.0

1.1.0.0

  Sources   Download

The Requires

 

by Biluk Andrey

27/04 2014

1.0.0

1.0.0.0

  Sources   Download

The Requires

 

by Biluk Andrey