PHPackages                             scaytrase/symfony-switchable-theme - 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. scaytrase/symfony-switchable-theme

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

scaytrase/symfony-switchable-theme
==================================

Web-configurable forms

3.0.1(10y ago)0648GPL-2.0+PHPPHP &gt;=5.3.3

Since Nov 13Pushed 9y ago1 watchersCompare

[ Source](https://github.com/scaytrase/symfony-switchable-theme)[ Packagist](https://packagist.org/packages/scaytrase/symfony-switchable-theme)[ RSS](/packages/scaytrase-symfony-switchable-theme/feed)WikiDiscussions master Synced 4w ago

READMEChangelog (4)Dependencies (9)Versions (7)Used By (0)

scaytrase/symfony-switchable-theme
==================================

[](#scaytrasesymfony-switchable-theme)

Runtime choosing for Twig `{% extends %}` clause
------------------------------------------------

[](#runtime-choosing-for-twig--extends--clause)

![Packagist](https://camo.githubusercontent.com/de672cddd7fbe1dd064876700f25666f5982fa175bf70f7e12f3e1197e9443dd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64642f7363617974726173652f73796d666f6e792d73776974636861626c652d7468656d652e737667)![Packagist](https://camo.githubusercontent.com/18c22d912204292041eb0c80d90eecb40dccc7b7d3f0815f424289c835876dad/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f7363617974726173652f73796d666f6e792d73776974636861626c652d7468656d652e737667)![Packagist](https://camo.githubusercontent.com/d6467efbcf3f338346b22f031025dd0283ac960888e4083502c6456820a0df71/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7363617974726173652f73796d666f6e792d73776974636861626c652d7468656d652e737667)

![Packagist](https://camo.githubusercontent.com/99c58960c70dd5ec633d84416f10908acb791b0f7257ca49a54872953d00c9f6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7363617974726173652f73796d666f6e792d73776974636861626c652d7468656d652e737667)![Packagist](https://camo.githubusercontent.com/3f511a31210bc9f00d900cb93a54fc59b9f3a43ecfaa9ff61fb1f4618f9ed193/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f7363617974726173652f73796d666f6e792d73776974636861626c652d7468656d652e737667)

[![SensioLabsInsight](https://camo.githubusercontent.com/cea2a4e631ce9889479e4eb055ee6b8c38c32bf8ce01a219bb1410ad07b0f2bd/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f33343464616336642d306532372d346235392d383462622d3664306564323839383063302f6269672e706e67)](https://insight.sensiolabs.com/projects/344dac6d-0e27-4b59-84bb-6d0ed28980c0)

Run-time switchable and user-configurable twig layouts

Originally developed to use with [BraincraftedBootstrapBundle](http://bootstrap.braincrafted.com/) theme switcher allows you to dynamically define twig extended templates at runtime. Also you can compile assets for your theme if you need. Current version supports theme configuration, so themes can be preconfigured (and have multiple configuration instances for single theme) as same as each configuration can be compiled separately.

Usage
-----

[](#usage)

### Basic example

[](#basic-example)

See [tests](src/ScayTrase/SwitchableThemeBundle/Tests/Core/ThemeTest.php) for basic usage example. You can find simple `ThemeInterface` implementation and logic example.

### Commons

[](#commons)

To use theme switch you should simply extend a template name, returned by `ThemeRegistry::getTemplate(theme,layout)` method. This method returns a string representing really extended template (i.e. `SomeTheme::some_layout.html.twig`) or null

```
class MyTheme implements ThemeInterface {
    public function get($layout = 'base') {return 'MyBundle:MyTheme:base.html.twig';}
    public function all() {return array('base' => 'MyBundle:MyTheme:base.html.twig');}
    public function getType() {return 'my_theme';}
}
```

```
{# MyBundle:MyTheme:base.html.twig #}
Here your theme basic template goes.
```

```
{# MyBundle::base.twig.html #}
{% extends theme_registry.template('my_theme','base') %}
```

### Fallback layout

[](#fallback-layout)

To use theme switch in case you are not shure, that template exists you can use multi-extends twig clause and supply it with fallback template, i.e.

```
{# MyBundle::base.twig.html #}
{% extends [theme_registry.template('my_theme','base'), 'MyBundle::fallback.html.twig'] %}
```

The main idea is that 'my\_theme' and 'base' strings could be replaced with variables populated from DB or user session. This allows you to dynamically select parent template for given conditions

### Configurable themes

[](#configurable-themes)

To use theme with theme configurations (theme instances) you should provide `ThemeInstance` object for the first argument to getTemplate. Configurable themes should implement `ConfigurableThemeInterface` to be able to be configured.

```
{# MyBundle::base.twig.html #}
{% extends theme_registry.template(themeInstance,'layout') %}
```

### Compilable themes

[](#compilable-themes)

Some themes should be processed before they can be used. For example, some theme assets should be compiled. To handle theese situations `CompilableThemeInterface` was created. Theme can be compiled by calling `CompilableThemeInterface::compile()` method. This way is best used with configurable interface, so you can compile different configurations of single theme.

As quick example there is an [abstract base class](src/ScayTrase/Themes/Bootstrap/Core/AbstractConfigurableBootstrapTheme.php) for creating Bootstrap 3.0 based theme. You could implement the accessing methods which points the class to the bootstrap less template, vendor assets, etc and results in correctly compiled `bootstrap.css` on `CompilableThemeInterface::compile()` call.

Theme compilation method based on bootstrap compilation workflow from [braincrafted/bootstrap-bundle](https://github.com/braincrafted/bootstrap-bundle)

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~59 days

Total

5

Last Release

3959d ago

Major Versions

2.0.2 → 3.0.0-rc2015-01-21

### Community

Maintainers

![](https://www.gravatar.com/avatar/ed906771163ff68cfb365bdd3b8278a3ce1b464f94051ff7ab50c03a30110efe?d=identicon)[scaytrase](/maintainers/scaytrase)

---

Top Contributors

[![scaytrase](https://avatars.githubusercontent.com/u/6578413?v=4)](https://github.com/scaytrase "scaytrase (41 commits)")

### Embed Badge

![Health badge](/badges/scaytrase-symfony-switchable-theme/health.svg)

```
[![Health](https://phpackages.com/badges/scaytrase-symfony-switchable-theme/health.svg)](https://phpackages.com/packages/scaytrase-symfony-switchable-theme)
```

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M647](/packages/sylius-sylius)[prestashop/prestashop

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.0k15.4k](/packages/prestashop-prestashop)[ec-cube/ec-cube

EC-CUBE EC open platform.

78527.0k1](/packages/ec-cube-ec-cube)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[contao/core-bundle

Contao Open Source CMS

1231.6M2.3k](/packages/contao-core-bundle)[netgen/layouts-core

Netgen Layouts enables you to build and manage complex web pages in a simpler way and with less coding. This is the core of Netgen Layouts, its heart and soul.

3689.4k10](/packages/netgen-layouts-core)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
