There is no license information available for the latest version (v0.1.0) of this package.

A bundle to manage multiple sites with different brandings and locales

Installs: 3 023

Dependents: 0

Stars: 62

Watchers: 5

Forks: 12

Open Issues: 4

v0.1.0 2014-04-12 09:36 UTC


View slides

This bundle allows you to manage multiple brandings and multiple locales in a Symfony2 application.


  • FrameworkExtraBundle
  • TwigBundle


  • Multiple routes for each site
  • Configuration per site
  • Templates per site


Add to your composer.json:

    "require": {
        "alexandresalome/multisite-bundle": "~0.1"

Add the bundle to your kernel:

# app/AppKernel.php

class AppKernel extends Kernel
    public function registerBundles()
        $bundles = array(
            # ...
            new Alex\MultisiteBundle\AlexMultisiteBundle(),


Add this section to your config.yml file:

    default_branding: branding_A
    default_locale:   fr_FR
            register: true
            en_GB: { host: }
            fr_FR: { host:, prefix: /fr }
                register: false
            en_GB: { host: }
            de_DE: { host:, register: false }

In this section, you must configure your brandings and locales.

You can also add extra options, like the register option here.

Declare your routes

In your controllers, substitute

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;


use Alex\MultisiteBundle\Annotation\Route;

You can then configure a multisite route in two ways:

 * @Route(name="login", paths={
 *   "fr_FR"="/connexion",
 *   "en_GB"="/login"
 * })
public function loginAction()
# ...

The path will be the same for all brandings, but will be localized. If you want a different path for same locale in different sites:

 * @Route(name="login", paths={
 *   "branding_A"={
 *     "fr_FR"="/connexion-on-A",
 *     "en_GB"="/login-on-A",
 *   },
 *   "branding_B"={
 *     "en_GB"="/login-on-B",
 *   },
 * })
public function loginAction()
# ...

Override templates

If you want to change a template for a specific site, create a similarly named file with branding/locale option in it:

Given your default template is AcmeDemoBundle::contact.html.twig.

You can override it with branding, locale, or both:

  • AcmeDemoBundle::_branding_locale/contact.html.twig
  • AcmeDemoBundle::_branding_/contact.html.twig
  • AcmeDemoBundle::__locale/contact.html.twig

Just create the file and it will automatically be loaded in place of the previous one.

Read the site context

From templates, use the global variable site_context, which returns a Alex\MultisiteBundle\Branding\SiteContext instance:

You are currently on {{ site_context.currentBrandingName }}
Your locale is {{ site_context.currentLocale }}

You can also read options from config with:

The option register is {{ site_context.option('register') ? 'enabled': 'not enabled' }}

In your controllers, use service site_context:

public function indexAction()