Style Backend Depending on the Application Environment
Sometimes it makes sense to style the OpenDxp backend UI depending on the application environment (APP_ENV) so that
backend users can easily differentiate by the looks.
Imagine having additional environments for Staging and Testing and you want to give editors a hint that they are working in the correct environment.
This can be easily implemented as the backend's body element contains a data attribute
data-app-env with the current application environment (e.g. <body class="opendxp_version_1" data-app-env="dev">) and thus can be referenced with a CSS selector.

Add an event subscriber
services:
# Event subscribers
App\EventSubscriber\:
resource: '../src/EventSubscriber/*'
tags: [ 'kernel.event_subscriber' ]
And subscribe to \OpenDxp\Bundle\AdminBundle\Event\BundleManagerEvents::CSS_PATHS event in order to load a custom CSS file (e.g.
/css/env.css).
<?php
namespace App\EventSubscriber;
class AdminAssetsSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
{
public static function getSubscribedEvents(): array
{
return [
\OpenDxp\Bundle\AdminBundle\Event\BundleManagerEvents::CSS_PATHS => 'onCssPaths',
];
}
public function onCssPaths(\OpenDxp\Event\BundleManager\PathsEvent $event): void
{
$event->addPaths(['/css/env.css']);
}
}
Create a CSS file /css/env.css. In this example, we intentionally style the OpenDxp backend's UI body with a standout
background.
body:not([data-app-env='prod']) #opendxp_body {
background: repeating-linear-gradient(
-45deg,
#005baa,
#005baa 5px,
#0c0f12 30px,
#0c0f12 10px
);
}