PHPackages                             monkblog/theme-manager - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. monkblog/theme-manager

AbandonedArchivedLibrary[Utility &amp; Helpers](/categories/utility)

monkblog/theme-manager
======================

A simple theme manager

v1.1.2(10y ago)0972[2 issues](https://github.com/monkblog/theme-manager/issues)1MITPHPPHP &gt;=5.5.9

Since Jun 28Pushed 4y ago1 watchersCompare

[ Source](https://github.com/monkblog/theme-manager)[ Packagist](https://packagist.org/packages/monkblog/theme-manager)[ RSS](/packages/monkblog-theme-manager/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (10)Dependencies (6)Versions (16)Used By (1)

A simple theme manager that can be used with [Laravel 5](http://laravel.com/).

[![Circle CI](https://camo.githubusercontent.com/f86c21c7560e5008b733e71543106dc6ed522a56f5608317a56ed763ad8c214c/68747470733a2f2f636972636c6563692e636f6d2f67682f6d6f6e6b626c6f672f7468656d652d6d616e616765722e7376673f7374796c653d737667)](https://circleci.com/gh/monkblog/theme-manager)[![StyleCI](https://camo.githubusercontent.com/981a25d7e09710414c39aaa5ce8b4643d1fa87b6be9d6db6739357dfb6001019/68747470733a2f2f7374796c6563692e696f2f7265706f732f33373233323838362f736869656c64)](https://styleci.io/repos/37232886)[![Code Climate](https://camo.githubusercontent.com/26fa4766c876b139b0130790954b25966287cdcc43d635f392e13021607dd3cf/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f6d6f6e6b626c6f672f7468656d652d6d616e616765722f6261646765732f6770612e737667)](https://codeclimate.com/github/monkblog/theme-manager)[![Test Coverage](https://camo.githubusercontent.com/3e67afdf0a059de89497092ef60e3fe9fc6f68c0aa481ed86c983f597f675cc6/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f6d6f6e6b626c6f672f7468656d652d6d616e616765722f6261646765732f636f7665726167652e737667)](https://codeclimate.com/github/monkblog/theme-manager/coverage)[![Total Downloads](https://camo.githubusercontent.com/2ca9d2014f1c81e4ac86796886aba5ff296cb79893d2c0ae81fbca7d75f03ded/68747470733a2f2f706f7365722e707567782e6f72672f6d6f6e6b626c6f672f7468656d652d6d616e616765722f642f746f74616c2e737667)](https://packagist.org/packages/monkblog/theme-manager)[![Latest Stable Version](https://camo.githubusercontent.com/dfd72a5c70aae0bffdff0ddb4bcb8346a22f1e02a4be137d2884570ace255283/68747470733a2f2f706f7365722e707567782e6f72672f6d6f6e6b626c6f672f7468656d652d6d616e616765722f762f737461626c652e737667)](https://packagist.org/packages/monkblog/theme-manager)[![Latest Unstable Version](https://camo.githubusercontent.com/3ed71e6b4075549becc46665a16041445dd629255e04aef019d85fd9a6bc9623/68747470733a2f2f706f7365722e707567782e6f72672f6d6f6e6b626c6f672f7468656d652d6d616e616765722f762f756e737461626c652e737667)](https://packagist.org/packages/monkblog/theme-manager)[![License](https://camo.githubusercontent.com/f2f61957fc4d35b1d480ed18ffd5eeeabd93047a1b24b4683d0ebbd3060186d8/68747470733a2f2f706f7365722e707567782e6f72672f6d6f6e6b626c6f672f7468656d652d6d616e616765722f6c6963656e73652e737667)](https://packagist.org/packages/monkblog/theme-manager)

Requirements
============

[](#requirements)

- Use with Laravel requires version 5 or above.
- PHP 5.5.9 or greater

Installation
============

[](#installation)

Require this package with Composer

```
composer require monkblog/theme-manager 1.1.*

```

Show me the examples already!!
==============================

[](#show-me-the-examples-already)

[examples.php](https://github.com/monkblog/theme-manager/blob/master/examples.php)

Documentation
=============

[](#documentation)

- [Requiring Theme Meta Data Field(s)](https://github.com/monkblog/theme-manager#requiring-theme-meta-data-fields)
    - [Injecting Required Field(s) into Starter Class](https://github.com/monkblog/theme-manager#injecting-required-fields-into-starter-class)
- [Error Handling](https://github.com/monkblog/theme-manager#error-handling)
- [Folder Structure](https://github.com/monkblog/theme-manager#folder-structure)
- [Bootstrapping Theme Classes](https://github.com/monkblog/theme-manager#bootstrapping-theme-classes)
- [Using with Laravel](https://github.com/monkblog/theme-manager#using-with-laravel)
    - [Usages](https://github.com/monkblog/theme-manager#usages)
    - [Publish Config](https://github.com/monkblog/theme-manager#publish-config)
    - [Override the base themes path](https://github.com/monkblog/theme-manager#override-the-base-themes-path)
    - [Adding more Themes folder to Manager](https://github.com/monkblog/theme-manager#adding-more-themes-folder-to-manager)
- [License](https://github.com/monkblog/theme-manager#license)

Requiring Theme Meta Data Field(s)
----------------------------------

[](#requiring-theme-meta-data-fields)

This package requires that a `theme.yml`/`theme.yaml` file have at least a `name` field defined.

As of version 1.1 you can define a list of required fields that need to be defined in each `theme.yml` file. This package will handle and separate the invalid themes from the valid ones.

Go to `config/theme-manager.php` and change `required_fields` to the array of required field(s) to be enforced. (see [Publish Config](https://github.com/monkblog/theme-manager#publish-config) section if config is not in your config folder).

#### Injecting Required Field(s) into Starter Class

[](#injecting-required-fields-into-starter-class)

If you're not using the Laravel Service Provider, you can pass an array to the `\ThemeManager\Starter` `start()` method:

```
$basePath = null;
$requiredFields = [ 'display_name', 'version', 'license', ];

$starter = ( new \ThemeManager\Starter )->start( $basePath, $requiredFields );

$themeManager = new \ThemeManager\ThemeManager( $starter );
```

You may also use the helper function as a shortcut:

```
$themeManager = theme_manager( null, [ 'display_name', 'version', 'license', ] );
```

Error Handling
--------------

[](#error-handling)

As of version 1.1 there's a `boolean $exceptionOnInvalid` which by default is `false`. To have the package throw exceptions for invalid themes change `exception_on_invalid` in `config/theme-manager.php` to be `true` or pass `true` as the `$exceptionOnInvalid`argument on the `start` method of `\ThemeManager\Starter` class.

Folder Structure
----------------

[](#folder-structure)

This package assumes that you have a `themes` folder at the root of your project containing all your theme folders.

*The 'base path' can be overwritten via `config/theme-manager.php` or the `start( __DIR__ . '/folder/' )` method on the `\ThemeManager\Starter` class*

e.g.

```
# themes/my-theme/theme.yml
name: my-theme
```

- app/
- public/
- themes/
    - my-theme/
        - theme.yml
    - my-theme-with-autoload/
        - composer.json
        - helpers.php
        - src/
            - MyThemeNamespace/
                - MyClass.php
                - MyThemeServiceProvider.php
        - theme.yml
        - vendor/
    - my-other-theme/
        - theme.yml
- vendor/

Bootstrapping Theme Classes
---------------------------

[](#bootstrapping-theme-classes)

Bootstrapping theme Service Provider(s) or other important classes before the application runs:

*For Laravel users: this code snippet is probably best placed at the bottom of `bootstrap/autoload.php`*

```
( new \ThemeManager\Starter )->bootstrapAutoload();
```

OR

```
theme_manager_starter()->bootstrapAutoload();
```

You can also optionally pass in a path to your themes folder if it's different than the default:

```
theme_manager_starter()->bootstrapAutoload( '/path/to/theme-folder' );
```

Using with Laravel
------------------

[](#using-with-laravel)

Once Composer has installed or updated your packages, you need to register ThemeManager with Laravel. Go into your `config/app.php`, find the `providers` key and add:

```
'ThemeManager\ServiceProvider',

```

You can add the ThemeManager Facade, to have easier access to the ThemeManager globally:

```
'ThemeManager' => 'ThemeManager\Facade\ThemeManager',

```

#### Usages:

[](#usages)

```
ThemeManager::all();
ThemeManager::getAllThemeNames();

ThemeManager::themeExists( 'theme-name' );
$theme = ThemeManager::getTheme( 'theme-name' );
$themeName = $theme->getName();
```

#### Publish Config

[](#publish-config)

Run:

```
php artisan vendor:publish --tag=theme

```

#### Override the base themes path:

[](#override-the-base-themes-path)

(See [Publish Config](https://github.com/monkblog/theme-manager#publish-config) section if `theme-manager.php` isn't present)

Go to `config/theme-manager.php` and change the `base_path` to the folder you want to use.

```
