Download the PHP package zanysoft/laravel-theme without Composer

On this page you can find all versions of the php package zanysoft/laravel-theme. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?
zanysoft/laravel-theme
Rate from 1 - 5
Rated 5.00 based on 1 reviews

Informations about the package laravel-theme

Description

Laravel License Downloads

This is a Laravel package that adds basic support for managing themes. It allows you to build your views & your assets in seperate folders, and supports for theme extending! Awesome :)

Features:

1 Installation

This package is very easy to set up. There are only couple of steps.

Install with Composer

If you’re on Laravel 5.4 or earlier, you’ll need to add the following to your config/app.php (for Laravel 5.5 and up these will be auto-discovered by Laravel):

Publish the package config file to your application. Run these commands inside your terminal.

php artisan vendor:publish --provider="ZanySoft\LaravelTheme\ThemeServiceProvider" That's it. You are now ready to start theming your applications!

2 Creating a theme

There are two equivalent ways to define a theme. You may pick the one that suits better to you

A) Configure a theme with a theme.json file

Tip: You should use php artisan theme:create command to create a theme. These are the manual steps:

Into the root of your views path create a new folder and then place a theme.json file inside with some configuration:

Important notes:

B) Configure a theme within the config/themes.php file

You may want to override previous settings (or define a new theme) into your config/themes.php. Just add your theme into the themes array. The format for every theme is very simple:

all settings are optional and can be omitted.

Implicit Theme decleration

Defining a theme is completely optional.

You may not create a configuration file as long as the defaults fits you! If a theme has not been registered at all then the default values will be used when you activate it.

For example if you Theme::set('my-theme') and you haven't created a theme.json file, nor declared 'my-theme' at the config\themes.php file, then the default locations will be assumed:

Custom configuration settings

You can add your own configuration into a theme (either into the theme.json file or into the config/themes.php).

This is an example theme.json with added configuration:

You can access these settings at runtime with:

Cache Settings

Warning: Theme settings are cached for faster loading times. If you change any setting you should refresh the cache in order to take effect.

Use php artisan theme:refresh-cache command for refresh cache. You can disable caching on config\themes.php

3 Build views

Whenever you need the path of a file (image/css/js etc) with root you can retrieve its path with:

Whenever you need the url of a local file (image/css/js etc) you can retrieve its path with:

The path-to-file should be relative to Theme Folder (NOT to public!). For example, if you have placed an image in public/theme-name/img/logo.png your Blade code would be:

When you are referring to a local file it will be looked-up in the current theme hierarchy, and the correct path will be returned. If the file is not found on the current theme or its parents then you can define in the configuration file the action that will be carried out: THROW_EXCEPTION | LOG_ERROR as warning (Default) | IGNORE assumes the file does exist on pubilc folder and returns the path

Some useful helpers you can use:

Fully qualified URLs:

The generated URLs will be fully qualified. if you need relative to the document root then enter second parameter to false (by default is true):

Your domain is retrieved from the url setting at the app.php config file (by default it will read your .env file entry)

URL queries

You may include queries in any url function. ie:

Parametric filenames You can include any configuration key (see Custom Theme Settings) of the current theme inside any path string using {curly brackets}. For example:

if there is a "version" key defined in the theme's configuration it will be evaluated and then the filename will be looked-up in the theme hierarchy. (e.g: many commercial themes ship with multiple versions of the main.css for different color-schemes, or you can use language-dependent assets)

4. Extending Themes

You can set a theme to extend an other. Check section How to Create a theme for instructions. A child theme may override parent's theme Assets and Views.

When you are requesting a view/asset that doesn't exist in your active theme, then it will be resolved from it's parent theme. You can easily create variations of your theme by simply overriding your views/themes that are different.

Assets

This is example will help you understand the theme hierarcy behaviour:

Consider these scenarios:

All themes fall back to the default laravel folders if a resource is not found on the theme folders. So for example you can leave your common libraries (jquery/bootstrap ...) in your public folder and use them from all themes. No need to duplicate common assets for each theme!

Views

The same behaviour aplies to your views too. When Laravel renders a view it will browse the active Theme's hierarcy until it will find the correct blade file and render it. This can even be a partial view (requested via @include or @extends) or a @component. All themes will fallback to Laravel default folders (eg resources\views).

5 Setting the active theme

Working with themes is very straightforward. Use:

You should set your active theme on each request. A good place for this is a Middleware. You can even define the Theme inside your Controller, before returning your views.

You can optional set a default theme in the theme.php configuration file, which will be activated during application bootstraping.

Using a Middleware to set a theme

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:

Now you can apply the middleware to a route or route-group. Eg:

Example: Let the user change the theme

Scenario: You have a theme switcher and when the user clicks on a theme, then he hits a route and the theme is applied on the whole application, for all the subsequent requests.

Note: This is just a boilerplate to help you get started. You may need to adapt it to your needs...

Route:

Controller:

Set the theme on a custom middleware

First create your middlware. ie: artisan make:middleware SetThemeFromSession

Then in the handle method of your middleware, read the theme name which is stored in the session:

Now you need to register your middleware inside the app\Http\Kernel.php file. For example if you want to apply your theme to all your routes, then you should add it into the web array:

6 Console Comands

theme:list

will show a list of your installed themes.

Example output:

theme:create [THEME-NAME]

Will gather some information and create a new theme.

This is an example:

theme:remove [THEME-NAME]

Will delete theme view & asset folders.

theme:package [THEME-NAME]

A distributable theme package will be created.

Theme packages are archives that contain both the Views & Assets folder of a Theme. You may distribute a theme as a package and install it to any laravel application. Theme packages will be stored into storage/themes path.

theme:install

Will install a theme from a theme package. Views & Assets folders will be created for the theme. Theme information will be extracted from the themes.json file inside the archive.

theme:refresh-cache

Rebuilds the theme cache. Theme cache stores all themes settings in a single file to reduce filesystem querying. Theme caching can be disabled at config\themes.php


All versions of laravel-theme with dependencies

PHP Build Version
Package Version
Requires php Version >=7.4
illuminate/support Version ^6.0|^7.0|^8.0|^9.0|^10.0
illuminate/contracts Version ^6.0|^7.0|^8.0|^9.0|^10.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package zanysoft/laravel-theme contains the following files

Loading the files please wait ....