• Stars
    star
    291
  • Rank 137,929 (Top 3 %)
  • Language
    PHP
  • License
    MIT License
  • Created about 13 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Provides theming support for Symfony bundles

Theme Bundle

This project is not longer maintained and recommends to use SyliusThemeBundle instead for support of Symfony 5 and Twig 3. For migration have a look at Migrate to SyliusThemeBundle.

This bundle provides you the possibility to add themes to each bundle. In your bundle directory it will look under Resources/themes/<themename> or fall back to the normal Resources/views if no matching file was found.

Build Status

Installation

Installation is a quick (I promise!) 3 step process:

  1. Download LiipThemeBundle
  2. Enable the Bundle
  3. Import LiipThemeBundle routing

Step 1: Install LiipThemeBundle with composer

Run the following composer require command:

$ php composer.phar require liip/theme-bundle

Step 2: Enable the bundle

Finally, enable the bundle in the kernel:

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new Liip\ThemeBundle\LiipThemeBundle(),
    );
}

Step 3: Import LiipThemeBundle routing files

Now that you have activated and configured the bundle, all that is left to do is import the LiipThemeBundle routing files.

In YAML:

# app/config/routing.yml
liip_theme:
    resource: "@LiipThemeBundle/Resources/config/routing.xml"
    prefix: /theme

Or if you prefer XML:

<!-- app/config/routing.xml -->
<import resource="@LiipThemeBundle/Resources/config/routing.xml" prefix="/theme" />

Configuration

You will have to set your possible themes and the currently active theme. It is required that the active theme is part of the themes list.

# app/config/config.yml
liip_theme:
    themes: ['standardTheme', 'winter_theme', 'weekend']
    active_theme: 'standardTheme'

Device specific themes/templates

You can provide specific themes or even templates for different devices (like: desktop, tablet, phone, plain). Set option autodetect_theme to true for setting current_device parameter based on the user agent:

# app/config/config.yml
liip_theme:
    autodetect_theme: true

Then in path_patterns you can use %%current_device%% parameter (with your device type as value)

# app/config/config.yml
liip_theme:
    path_patterns:
        app_resource:
            - %%app_path%%/themes/%%current_theme%%/%%current_device%%/%%template%%
            - %%app_path%%/themes/fallback_theme/%%current_device%%/%%template%%
            - %%app_path%%/views/%%current_device%%/%%template%%

Optionally autodetect_theme can also be set to a DIC service id that implements the Liip\ThemeBundle\Helper\DeviceDetectionInterface interface.

Get active theme information from cookie

If you want to select the active theme based on a cookie you can add:

# app/config/config.yml
liip_theme:
    cookie:
        name: NameOfTheCookie
        lifetime: 31536000 # 1 year in seconds
        path: /
        domain: ~
        secure: false
        http_only: false

Disable controller based theme switching

If your application doesn't allow the user to switch theme, you can deactivate the controller shipped with the bundle:

# app/config/config.yml
liip_theme:
    load_controllers: false

Theme Cascading Order

The following order is applied when checking for templates that live in a bundle, for example @BundleName/Resources/template.html.twig with theme name phone is located at:

  1. Override themes directory: app/Resources/themes/phone/BundleName/template.html.twig
  2. Override view directory: app/Resources/BundleName/views/template.html.twig
  3. Bundle theme directory: src/BundleName/Resources/themes/phone/template.html.twig
  4. Bundle view directory: src/BundleName/Resources/views/template.html.twig

For example, if you want to integrate some TwigBundle custom error pages regarding your theme architecture, you will have to use this directory structure : app/Resources/themes/phone/TwigBundle/Exception/error404.html.twig

The following order is applied when checking for application-wide base templates, for example ::template.html.twig with theme name phone is located at:

  1. Override themes directory: app/Resources/themes/phone/template.html.twig
  2. Override view directory: app/Resources/views/template.html.twig

Change Theme Cascading Order

You able change cascading order via configurations directives: path_patterns.app_resource, path_patterns.bundle_resource, path_patterns.bundle_resource_dir. For example:

# app/config/config.yml
liip_theme:
    path_patterns:
        app_resource:
            - %%app_path%%/themes/%%current_theme%%/%%template%%
            - %%app_path%%/themes/fallback_theme/%%template%%
            - %%app_path%%/views/%%template%%
        bundle_resource:
            - %%bundle_path%%/Resources/themes/%%current_theme%%_%%current_device%%/%%template%%
            - %%bundle_path%%/Resources/themes/%%current_theme%%/%%template%%
            - %%bundle_path%%/Resources/themes/fallback_theme/%%template%%
        bundle_resource_dir:
            - %%dir%%/themes/%%current_theme%%/%%bundle_name%%/%%template%%
            - %%dir%%/themes/fallback_theme/%%bundle_name%%/%%template%%
            - %%dir%%/%%bundle_name%%/%%override_path%%
Cascading Order Patterns Placeholders
Placeholder Representation Example
%app_path% Path where application resources are located app/Resources
%bundle_path% Path where bundle located, for example src/Vendor/CoolBundle/VendorCoolBundle
%bundle_name% Name of the bundle VendorCoolBundle
%dir% Directory, where resource should looking first
%current_theme% Name of the current active theme
%current_device% Name of the current device type desktop, phone, tablet, plain
%template% Template name view.html.twig
%override_path% Like template, but with views directory views/list.html.twig

Change Active Theme

For that matter have a look at the ThemeRequestListener.

If you are early in the request cycle and no template has been rendered you can still change the theme without problems. For this the theme service exists at:

$activeTheme = $container->get('liip_theme.active_theme');
echo $activeTheme->getName();
$activeTheme->setName("phone");

Theme Specific Controllers

In some situations, a different template is not enough and you need a different controller for a specific theme. We encountered this with A/B testing. Do not abuse this feature and check whether your use case is still to be considered a theme.

This feature is not active by default as there is an additional request listener involved. Enable it by setting theme_specific_controllers in your configuration:

# app/config/config.yml
liip_theme:
    # ...
    theme_specific_controllers: true

Now you can configure controllers per theme in your routing file:

my_route:
    path: /x/y
    defaults:
        _controller: my_service:fooAction
        theme_controllers:
            a: my_other_service:fooAction
            b: App:Other:foo

As usual, you can use both the service notation or the namespace notation for the controllers. Just specify the controller by theme under the key theme_controllers.

Assetic integration

Because of the way the LiipThemeBundle overrides the template locator service, assetic will only dump the assets of the active theme.

In order to dump the assets of all themes enable the assetic_integration option:

# app/config/config.yml
liip_theme:
    # ...
    assetic_integration: true

This will override the Twig formula loader and iterate over all of the themes, ensuring that all of the assets are dumped.

Note that this only works with AsseticBundle 2.1 or higher.

Override the Device Detection

It is possible to override the service used for the device detection. Make sure to either extend DeviceDetection or implement DeviceDetectionInterface:

# app/config/config.yml
services:
    my_devcice_detection:
        class: SomeClass

liip_theme:
    # ...
    device_detection: my_devcice_detection

Migrate to SyliusThemeBundle

This will show you the stepts to switch from the LiipThemeBundle to SyliusThemeBundle.

Remove the old theme bundle and install the SyliusThemeBundle:

# Remove old theme-bundle
composer remove liip/theme-bundle --no-update

# Install new theme-bundle
composer require sylius/theme-bundle:"^2.0"

Remove old configuration

The old liip_theme.yaml configuration needs to be removed:

-liip_theme:
-    themes: ['awesome']
-    active_theme: 'awesome'

In the next step you see how you configure the awesome theme using the SyliusThemeBundle.

Configure the SyliusThemeBundle:

In order to use the bundle you have to add the following default configuration:

# ./config/packages/sylius_theme.yaml

sylius_theme:
    sources:
        filesystem: ~

By default, the bundle seeks for the themes in the %kernel.project_dir%/themes directory and looks for a configuration file named composer.json. This can be changed via the yaml configuration:

sylius_theme:
    sources:
        filesystem:
            filename: theme.json

Convert Theme Configuration

In the SyliusThemeBundle every theme must have its own configuration file in form of a theme.json. Add a theme.json file and add the following minimal configuration:

{
    "name": "app/awesome"
}

Go to the Theme Configuration Reference for the detailed documentation about the configuration options.

Most likely you have to change the theme name. It is important, that the name matches the naming convention of composer (vendor/name). Furthermore the theme.json has to be moved into the directory for this specific theme.

For example: %kernel.project_dir%/themes/awesome/theme.json

Update project structure

Your templates have to be placed in a templates directory next to the theme.json file.

For example: %kernel.project_dir%/themes/<theme-name>/templates

This results in the following project structure:

ProjectName
β”œβ”€β”€ composer.json
β”œβ”€β”€ assets
β”œβ”€β”€ bin
β”œβ”€β”€ config
β”œβ”€β”€ templates
β”œβ”€β”€ themes
β”‚   β”œβ”€β”€ awesome
β”‚   β”‚   β”œβ”€β”€ templates
β”‚   β”‚   β”‚   └── base.html.twig
β”‚   β”‚   └── theme.json
β”‚   └── <theme-name-2>
β”‚       β”œβ”€β”€ templates
β”‚       β”‚   └── base.html.twig
β”‚       └── theme.json
β”œβ”€β”€ ...
└── ...

As you can see in the project structure, each theme must have their own theme.json configuration file next to the templates directory.

Create ThemeRequestListener

You need to create a ThemeRequestListener to set the theme based on the current $request data:

use Sylius\Bundle\ThemeBundle\Context\SettableThemeContext;
use Sylius\Bundle\ThemeBundle\Repository\ThemeRepositoryInterface;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\HttpKernelInterface;

final class ThemeRequestListener
{
    /** @var ThemeRepositoryInterface */
    private $themeRepository;

    /** @var SettableThemeContext */
    private $themeContext;

    public function __construct(ThemeRepositoryInterface $themeRepository, SettableThemeContext $themeContext)
    {
        $this->themeRepository = $themeRepository;
        $this->themeContext = $themeContext;
    }

    public function onKernelRequest(GetResponseEvent $event): void
    {
        if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
            // don't do anything if it's not the master request
            return;
        }

        $themeName = 'app/awesome';

        // here you can set the $themeName based on $event->getRequest() object

        $this->themeContext->setTheme(
            $this->themeRepository->findOneByName($themeName)
        );
    }
}

Have a look also at the SyliusThemeBundle Documentation.

Contribution

Active contribution and patches are very welcome. To keep things in shape we have quite a bunch of unit tests. If you're submitting pull requests please make sure that they are still passing and if you add functionality please take a look at the coverage as well it should be pretty high :)

First install dependencies:

   composer.phar install --dev

This will give you proper results:

phpunit --coverage-text

More Repositories

1

LiipImagineBundle

Symfony Bundle to assist in imagine manipulation using the imagine library
PHP
1,638
star
2

LiipFunctionalTestBundle

Some helper classes for writing functional tests in Symfony
PHP
636
star
3

TheA11yMachine

The A11y Machine is an automated accessibility testing tool which crawls and tests pages of any web application to produce detailed reports.
JavaScript
617
star
4

LiipMonitorBundle

Integrates the LiipMonitor library into Symfony
PHP
469
star
5

RMT

RMT is a handy tool to help releasing new version of your software
PHP
451
star
6

php-osx

DEPRECATED: See https://php-osx.liip.ch/ for details. The uploader and website for the PHP 5 package for OS X 10.6 built with https://github.com/liip/build-entropy-php
PHP
329
star
7

bootstrap-blocks-wordpress-plugin

Bootstrap Gutenberg Blocks for WordPress
PHP
271
star
8

sheriff

Conditional marshalling for Go
Go
242
star
9

LiipHelloBundle

[DEPRECATED] Alternative Hello World Bundle for Symfony2 using several FriendsOfSymfony Bundles
PHP
201
star
10

LiipTestFixturesBundle

This bundles enables efficient loading of Doctrine fixtures in functional test-cases for Symfony applications
PHP
160
star
11

serializer

A PHP serializer that generates PHP code for maximum performance
PHP
127
star
12

LiipCacheControlBundle

DEPRECATED! This bundle is superseded by FOSHttpCacheBundle. A migration guide is in the README of LiipCacheControlBundle
PHP
108
star
13

kanbasu

A lightweight CSS framework written in Sass.
SCSS
93
star
14

LiipDoctrineCacheBundle

[DEPRECATED] use https://github.com/doctrine/DoctrineCacheBundle
PHP
71
star
15

LiipMagentoBundle

[DEPRECATED] Proof of concept for integrating Magento into Symfony2 applications
PHP
67
star
16

LiipMonitor

Deprecated: Generic PHP library to run application health checks
PHP
62
star
17

Radios

An mp3 streaming Application for the iPhone and the iPad
Objective-C
59
star
18

drifter

Drifter is a framework to help provision developer boxes using Ansible and Vagrant
HTML
57
star
19

chusho

A library of bare & accessible UI components and tools for Vue.js 3
TypeScript
54
star
20

LiipUrlAutoConverterBundle

[DEPRECATED] This bundle will add a Twig Extension for templates with a new filter for automatically converting urls and emails in a string to html links
PHP
50
star
21

packaging

deb and rpm packaging solution for php projects
PHP
49
star
22

SEO-keywords-generator

Keyword generator providing multiple commands in order to manage keyphrases for SEO monitoring tools such as AWRCloud
Python
49
star
23

extend-block-example-wp-plugin

Example how to extend an existing Gutenberg block in WordPress
JavaScript
48
star
24

styleguide-starterkit

A starterkit to create styleguides with Fractal and Webpack.
JavaScript
37
star
25

LiipSearchBundle

[DEPRECATED] Google XML API for searching is discontinued
PHP
35
star
26

LiipProcessManager

Provides a simple locking mechanism based on UNIX process id's written to a "PID file".
PHP
33
star
27

LiipVieBundle

[DEPRECATED] in favor of SymfonyCmfCreateBundle
JavaScript
32
star
28

viewmodel-savedstate-helpers

Easily save your Android ViewModel state with Kotlin
Kotlin
32
star
29

fanci

Fanci is a lightweight node module to extract, rename and transform JSON based on a template
JavaScript
30
star
30

LiipContainerWrapperBundle

[DEPRECATED] Don't screw DI by just injecting everything.
PHP
29
star
31

LiipCodeBundle

[DEPRECATED] A set of Symfony2 console commands to help developers deal with the various ways of identifying classes, templates, bundles, services, etc. Provides console commands to find their file path or class, as well as editor shortcuts.
PHP
26
star
32

LiipTranslationBundle

Tools for translation management
PHP
25
star
33

guess-the-liiper-ios

Guess the Liiper iOS version made with React Native
JavaScript
25
star
34

dockerbox

A small vagrant based docker box for using docker on OS X and Windows (based on https://github.com/phusion/open-vagrant-boxes)
Shell
25
star
35

packager

Lightweight package installer written in python
Python
22
star
36

LiipXsltBundle

[DEPRECATED] Renderer for XSLT templates in Symfony2 (not actively maintained)
PHP
20
star
37

LiipHyphenatorBundle

[Deprecated] Adds support to Symfony for hyphenating long words using the Org_Heigl_Hyphenator library.
PHP
20
star
38

wrench

wrench: a CLI tool for Passbolt
Python
19
star
39

SweetPreferences

Add syntactic sugar to your Android SharedPreferences
Kotlin
19
star
40

barcode.js

POC for a JavaScript barcode reader, blog post to follow
JavaScript
19
star
41

presence

Presence shows you the availabilities of your set up team by analyzing their Google Calendar
PHP
18
star
42

django-ansible

Deploy Django projects generated by liip/django-template with Ansible
Python
18
star
43

django-template

Project template for Django projects
Python
17
star
44

animate-blocks-wordpress-plugin

Animate Gutenberg blocks plugin for WordPress
JavaScript
17
star
45

commit-hook-email

GitLab and Github Commit Email Hook
PHP
16
star
46

metadata-parser

A PHP metadata parser for domain models
PHP
16
star
47

DataAggregator

[DEPRECATED] The data aggregator cumulates/filters information provided by one or more loader and routes them to one or more persistence layers.
PHP
16
star
48

magento-xhprof

[In Development] Profile Magento with XHProf
PHP
15
star
49

bund-drupal-starterkit

PHP
14
star
50

styleguide

Liip Web Styleguide
SCSS
14
star
51

roger-q

Tool to work with RabbitMQ queues, including commands to dump, deduplicate and publish messages
PHP
14
star
52

ckanext-ddi

CKAN extension for DDI, developed for the World Bank
Python
12
star
53

liip10yearsgame

Jump and run through Liip's 10 year history
JavaScript
12
star
54

LiipSoapRecorderBundle

[DEPRECATED] Recorder/Player for SOAP communications
PHP
12
star
55

pontsun

The Liip docker local development orchestrator
12
star
56

LiipMultiplexBundle

[DEPRECATED] Symfony2 controller that allows calling multiple URL's in one request as well as JSON-ifying any controller
PHP
12
star
57

wp-tyk-dev-portal

A WordPress plugin that adds a developer portal for a Tyk API Gateway
PHP
12
star
58

LiipRokkaImagineBundle

integration between LiipImagineBundle and rokka.io
PHP
11
star
59

LiipKit

LiipKit regroups usefull classes/extensions used in many applications
Swift
11
star
60

LiipDrupalConnectorModule

An abstraction layer between the procedural world of Drupal and OOP.
PHP
11
star
61

serializer-jms-adapter

An adapter to make liip/serializer a drop-in replacement for jms/serializer
PHP
10
star
62

LiipFormTranslationChoiceBundle

[DEPRECATED] A Symfony2 bundle that provides a form widget and a validator that work with translation domains
PHP
10
star
63

packaging_demo

A demo project for the packaging solution at http://github.com/liip/packaging
PHP
9
star
64

LiipOneallBundle

[DEPRECATED] Symfony2 Bundle to integrate oneall.com
PHP
9
star
65

oc-blocks-theme

OctoberCMS theme that demonstrates the use of repeater groups to assemble static pages with customizable building blocks.
HTML
9
star
66

taxi-zebra

Zebra backend for Taxi
Python
8
star
67

niweaapp

The Tages-Anzeiger iPas App done in Niwea aka HTML5/CSS/JS
JavaScript
8
star
68

directus-utilities

Utility library for directus
TypeScript
8
star
69

frctl-twig

frctl-twig is an PHP Twig adapter for Fractal consisting of an NPM and a Composer package.
PHP
8
star
70

LiipFoxycartBundle

[DEPRECATED] Symfony Foxycart integration Bundle
PHP
8
star
71

discourse-multilingual-support

Provide some tools to have a better multilingual support on Discourse
Ruby
8
star
72

wrapper-block-example-wp-plugin

This is a WordPress plugin which shows how to create a wrapper block for Gutenberg.
JavaScript
7
star
73

e2e-tests-example-wp-plugin

Example how to write E2E tests for a Gutenberg block in WordPress
JavaScript
7
star
74

bower-lockfile-resolver

adds a missing feature of bower: a lockfile with all pacakages versions pinned
JavaScript
6
star
75

bund_ds

Vue
6
star
76

magerant

Magento Vagrant Setup (powered by Ansible)
Shell
6
star
77

jelapi

A Jelastic API Python library
Python
6
star
78

requests_gpgauthlib

A GPGAuth Client in Python
Python
5
star
79

ckan-vagrant

Vagrant based CKAN development environment
Ruby
5
star
80

LiipDrupalCrudAdminModule

The idea behind this module is to provide a most forward standard implementation to handle CRUD operations.
PHP
5
star
81

storybook-starterkit

A starterkit to create styleguides with Storybook and Twig.
JavaScript
5
star
82

directus-extension-gzip-hook

Directus extension gzip hook
TypeScript
4
star
83

liip-cookbooks

4
star
84

OpenLayersOfflineDemo

Demonstrate the offline storage with OpenLayers
JavaScript
4
star
85

fabliip

Set of Fabric functions to help deploying websites.
Python
4
star
86

Okapi

Okapi is a small framework for building web applications. It's built on PHP and XSLT and is fantastic for integration with REST web services.
PHP
4
star
87

html2kirby

Convert HTML markup to Kirby Markup
Python
4
star
88

liip-magento-shared

Liip Magento Shared
PHP
4
star
89

Backbone.localStorageSync

A caching layer between the client and server
JavaScript
4
star
90

Sodium.Xamarin

Xamarin compatible wrapper for libsodium
C#
3
star
91

LiipDrupalRegistryModule

This module provides an API to store key/value pairs of information.
PHP
3
star
92

magento-config-search

PHP
3
star
93

LiipTeraWurflBundle

[DEPRECATED] Symfony2 Bundle for the wurfl user agent. Not working! For reasons why check the url below ..
PHP
3
star
94

kanbasu-vue

Kanbasu components as Vue components
JavaScript
3
star
95

bund_drupal_starterkit_theme

CSS
3
star
96

smoke-detector

🚭 Allow us to be notified when there is smoke in the office.
Python
3
star
97

ushahidi-plugins-mobile

Mobile Accessible Version of Ushahidi
PHP
3
star
98

image-selector-example-wp-plugin

Example how to create an image selector for a Gutenberg block in WordPress
JavaScript
3
star
99

LiipDataAggregatorBundle

[DEPRECATED] The data aggregator cumulates information provided by a loader and routes them to a persistence layer
PHP
3
star
100

directus-extension-seo-interface

Provides a new directus interface for SEO fields
Vue
3
star