You can do it with a couple of simple modules. The basic idea is to associate a template to a domain (or subdomain), then listen to kernel events to set the template related to the current domain when a request is submitted.
To switch the current front template, you can use the TemplateSwitcher module : https://github.com/roadster31/TemplateS … stener.php
Then in your module create a listener which listens to KernelEvents::REQUEST or KernelEvents::CONTROLLER events, something like :
<?php
namespace YourModule\Listener;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use TemplateSwitcher\Event\TemplateSwitcherEvent;
class KernelListener implements EventSubscriberInterface
{
/** @var RequestStack */
protected $requestStack;
/** @var Container */
protected $dispatcher;
/**
* KernelListener constructor.
* @param RequestStack $requestStack
* @param EventDispatcherInterface $dispatcher
*/
public function __construct(RequestStack $requestStack, EventDispatcherInterface $dispatcher) {
$this->dispatcher = $dispatcher;
$this->requestStack = $requestStack;
}
/**
* @param FilterControllerEvent $event
*/
public function controller(FilterControllerEvent $event)
{
$request = $this->requestStack->getCurrentRequest();
$serverName = $request->getHost();
// Find the template related to the current server name (e.g., domain)
$frontTemplateName = ...
// Set the front template for the current user using the TemplateSwitcher module
$this->dispatcher->dispatch(
TemplateSwitcherEvent::SWITCH_TEMPLATE_EVENT,
new TemplateSwitcherEvent($frontTemplateName)
);
}
/**
* @inheritDoc
*/
public static function getSubscribedEvents()
{
return [
KernelEvents::CONTROLLER => ['controller', 192],
];
}
}
This way, you can share modules and data between several templates and domains.