Add theming support to your Laravel 5.* projects

Overview

Laravel Theme

Build Status Latest Stable Version License

Add theming support to your Laravel 5.* projects.

Features

  • Custom theme locations
  • Support for theme inheritence with theme fallback
  • Theme assets loading
  • Artisan console commands

Install

Require it via terminal like so:

$ composer require karlomikus/theme

Or add the package to your composer file:

"karlomikus/theme": "1.*"

Next add new service provider and facade to your config/app.php file:

// Service provider
Karlomikus\Theme\ThemeServiceProvider::class
// Facade
'Theme' => Karlomikus\Theme\Facade\Theme::class

Next you need to publish the config file:

$ php artisan vendor:publish

This will create a theme.php file in your config directory in which you can define your default path to themes directory.

Theme setup

Create new folder in your themes directory (default: public/themes) and add views folder (which will hold all your custom views) and theme.json file (contains information about a theme).

{
    "name": "Theme name",
    "author": "Karlo Mikuลก",
    "description": "Default theme description",
    "version": "1.0",
    "namespace": "theme-folder",
    "parent": null
}

This are all available attributes, but the required ones only include: name, author and namespace. Value of namespace must be the name of the theme's folder.

If you want your theme to depend on other theme views, just include a parent theme namespace in parent attribute.

Example folder structure:

- public/
    - themes/
        - theme-1/
            - views/
            - theme.json

Usage

The library will firstly check all available valid themes in theme directory.

You can then set a theme by it's namespace:

Theme::set('theme-namespace');

Then you call views like you usually do in laravel:

view('home');

This will firstly check if there is a home.blade.php in current theme directory. If none is found then it checks parent theme, and finally falls back to default laravel views location.

You can also inject theme instance using ThemeInterface.

use Karlomikus\Theme\Contracts\ThemeInterface;

private $theme;

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

Theme path

You can set default path to themes folder in config/theme.php file. Please note that currently themes folder must be somewhere inside public folder.

Available methods

Here's the list of methods you can access:

// Activate/set theme
Theme::set('theme-namespace');

// Get all available themes as an array
Theme::all();

// Get currently active
Theme::get();

// Get theme by namespace
Theme::get('specific-namespace');

// Override default theme path
Theme::setDefaultThemePath('new/path/to/themes');

// Check if theme exists
Theme::has('theme-namespace');

// Render theme path URL
theme_url('assets/style.css');

Artisan commands

Get a table of all found themes:

$ php artisan theme:list

+------------------+-------------+------------+
| Name             | Author      | Namespace  |
+------------------+-------------+------------+
| Bootstrap theme  | Karlo Mikus | bootstrap  |
| Default theme    | Test Author | default    |
| Foundation theme | Lorem Ipsum | foundation |
| Test theme       | Dolor Sitha | test       |
+------------------+-------------+------------+

Create a theme directory with config file:

$ php artisan theme:make

 Template name:
 > Theme name

 Template author:
 > Firstn Lastn

Theme created succesfully!

Changelog

Please see CHANGELOG for more information what has changed recently.

TODO

  • Contact me for ideas
You might also like...
A WordPress plugin to re-use the same domain name for both your website and your Rebrandly links
A WordPress plugin to re-use the same domain name for both your website and your Rebrandly links

By installing this plugin and configuring it to connect with your Rebrandly account, you will be able to create branded links using the same domain yo

โ“ A WordPress plugin to display your site's environment type in the admin bar

Where A WordPress plugin to display your site's environment type in the admin bar. Available Filters where_env_should_add_env_type - Defaults to true

The Pronamic WordPress Basecone plugin allows you to connect your WordPress installation to Basecone.

Pronamic WordPress Basecone The Pronamic WordPress Basecone plugin allows you to connect your WordPress installation to Basecone. Table of contents Au

A Wordpress plugin that allows you to customize a news feed on your home page

=== Plugin Name === Contributors: Noora Chahine Requires at least: 4.0.1 Tested up to: 5.4 Stable tag: 5.2 License: GPLv2 or later License URI: http:/

A foundation for WordPress Plugin Development that aims to provide a clear and consistent guide for building your plugins.

WordPress Plugin Boilerplate A standardized, organized, object-oriented foundation for building high-quality WordPress Plugins. Contents The WordPress

Wordless is a junction between a WordPress plugin and a theme boilerplate that dramatically speeds up and enhances your custom theme creation
Wordless is a junction between a WordPress plugin and a theme boilerplate that dramatically speeds up and enhances your custom theme creation

Wordless is a junction between a WordPress plugin and a theme boilerplate that dramatically speeds up and enhances your custom theme creation. Some of

๐Ÿ” Secure and ๐Ÿค‘ budget-friendly Wordpress setup for your digital garden ๐Ÿก
๐Ÿ” Secure and ๐Ÿค‘ budget-friendly Wordpress setup for your digital garden ๐Ÿก

wordpress-deploy ๐Ÿš€ Deploy wordpress sites to $5 servers in a few minutes ๐Ÿš€ Install | Deploy a site | Configuration options | FAQs Use this to setup

This WordPress Plugin Boilerplate is meant for you to develop your own plugin on.

WordPress Plugin Boilerplate This plugin boilerplate is meant for you to develop your own plugin on. Support & collaboration Features OOP plugin core

Disable direct access to your sites /wp-login.php script, plus user notifications based on actions.
Disable direct access to your sites /wp-login.php script, plus user notifications based on actions.

WordPress Login Locker Disable direct access to your sites /wp-login.php script plus user notifications based on actions. Package Installation (via Co

Comments
  • Laravel 5.8 not compatible.

    Laravel 5.8 not compatible.

    This karlomikus/theme is not compatible with Laravel 5.8 version. Please help on this.

    I got error.

    ErrorException : Declaration of Karlomikus\Theme\ThemeViewFinder::setPaths(array $paths) should be compatible with Illuminate\View\FileViewFinder::setPaths($paths)

    at C:\wamp\www\laravel_58\vendor\karlomikus\theme\src\Theme\ThemeViewFinder.php:33
    29| public function prependPath($path)
    30| {
    31| array_unshift($this->paths, $path);
    32| }
    33| }
    34|

    opened by rameshsrinivasan 1
  • Best Practices

    Best Practices

    I would like to set different themes for front and backend so would it be best practices to put the Theme::set(''); within grouped routes? Example: Route::group(['namespace' => 'Frontend', 'as' => 'frontend.'], function () { Theme::set('frontend'); includeRouteFiles(DIR.'/Frontend/'); });

    opened by objectorientedninja 0
  • Suggestion: Method names

    Suggestion: Method names

    Just a suggestion, but Laravel's conventions are generally put(), get(), has(), all().

    Would it make more sense, from a Laravel point of view, but use these names?

    Theme::getThemes(); becomes Theme:all() Theme::themeExists('theme-namespace'); becomes Theme::has('theme-namespace');

    Other than that, terrific job, can't wait to use this!

    enhancement 
    opened by kevinruscoe 0
Releases(v1.0.5)
Owner
Karlo Mikus
Software developer at Teslasoftware
Karlo Mikus
Laravel Blog Package. Easiest way to add a blog to your Laravel website. A package which adds wordpress functionality to your website and is compatible with laravel 8.

Laravel Blog Have you worked with Wordpress? Developers call this package wordpress-like laravel blog. Contact us for any customization: contact@binsh

Binshops 279 Dec 28, 2022
Developers tool for WordPress plugins: Wraps all your projects dependencies in your own namespace

Developers tool for WordPress plugins: Wraps all your projects dependencies in your own namespace, in order to prevent conflicts with other plugins loading the same dependencies in different versions.

Coen Jacobs 362 Dec 23, 2022
A simple little WordPress block that allows you add social share icons to your website.

Social Sharing Block This plugin requires WordPress 5.9+ or 5.8+ with Gutenberg active. A simple little block that allows you to add social share icon

Nick Diego 18 Dec 27, 2022
Style guide for writing consistent PHP for WordPress projects.

Inpsyde PHP Coding Standards PHP 7+ coding standards for Inpsyde WordPress projects. Installation The code styles are enforced via the popular php_cod

Inpsyde GmbH 77 Nov 14, 2022
WordPress & TypeScript. Simple starter template for WordPress projects

WordPress & TypeScript. Simple starter template for WordPress projects that want to use TypeScript in combination with @wordpress/scripts

Make it WorkPress 11 Sep 27, 2022
Add time dismissible admin notices to WordPress

WP Dismiss Notice Add time dismissible admin notices to WordPress. Fork of https://github.com/w3guy/persist-admin-notices-dismissal Instuctions Initia

Andy Fragen 6 Aug 24, 2022
A WordPress plugin that demonstrates how to easily add frontend interactivity with Alpinejs.

Add Alpinejs to Custom Gutenberg Blocks Is there a fun/easy/lightweight way to add frontend interactivity to custom Gutenberg blocks w/o using React o

null 9 Apr 20, 2022
WPGraphQL Extension: Adds "meta_query" support to postObject connection queries using WP_Query

WPGraphQL Meta Query This plugin adds Meta_Query support to the WP GraphQL Plugin for postObject query args. Why is this an extension and not part of

WPGraphQL 42 Nov 10, 2022
Adds `tax_query` support to postObject connection queries using WP_Query

WPGraphQL Tax Query This plugin adds Tax_Query support to the WP GraphQL Plugin for postObject query args (WP_Query). Pre-req's Using this plugin requ

WPGraphQL 39 Dec 2, 2022
Google Analytics 4 (GA4) AMP support WordPress plugin

Google Analytics 4 (GA4) AMP support WordPress plugin. Download from WordPress About Google Analytics 4 (GA4) AMP support WordPress plugin. Contributi

Roland Farkas 2 Jun 29, 2022