2017 © Pedro Peláez
 

symfony-bundle theme-bundle

Provides theming support for Symfony Bundles

image

shapecode/theme-bundle

Provides theming support for Symfony Bundles

  • Thursday, February 22, 2018
  • by Nicklog
  • Repository
  • 1 Watchers
  • 1 Stars
  • 42 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 50 % Grown

The README.md

Theme Bundle

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., (*1)

Installation

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

  1. Download ShapecodeThemeBundle
  2. Enable the Bundle

Step 1: Install ShapecodeThemeBundle with composer

Run the following composer require command:, (*3)

``` bash $ php composer.phar require shapecode/theme-bundle, (*4)


### Step 2: Enable the bundle Finally, enable the bundle in the kernel: ``` php <?php // app/AppKernel.php public function registerBundles() { $bundles = array( // ... new \Shapecode\Bundle\ThemeBundle\ShapecodeThemeBundle(), ); }

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., (*5)

``` yaml, (*6)

app/config/config.yml

shapecode_theme: themes: ['standardTheme', 'winter_theme', 'weekend'] active_theme: 'standardTheme', (*7)


### Get active theme information from cookie If you want to select the active theme based on a cookie you can add: ``` yaml # app/config/config.yml shapecode_theme: cookie: name: NameOfTheCookie lifetime: 31536000 # 1 year in seconds path: / domain: ~ secure: false http_only: 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:, (*8)

  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, (*9)

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

  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:, (*11)

``` yaml, (*12)

app/config/config.yml

shapecode_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%%/%%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%%, (*13)


##### 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
%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: ``` php $activeTheme = $container->get('shapecode_theme.active_theme'); echo $activeTheme->getName(); $activeTheme->setName("phone");

Contribution

Active contribution and patches are very welcome., (*14)

First install dependencies:, (*15)

   composer.phar install --dev

The Versions