I intend to style the site slightly differently on staging than on production, so that editors don’t confuse things. For that I’m thinking to add a body class if the page is loaded on staging so that I can apply styles. What’s the best way to do this? I know that you can have different config files for different environments/domains but can I use that somehow, and if yes, how?
To be clear: I’m not talking about the panel but the public facing side of the website.
You can do $site->url() in a ternearay statement in the body tag in the templates.
Something like:
<body class="<?= $site->url() === 'livedomain.com' ? 'live' : 'staging'; ?>">
Obviously amend ‘livedomain.com’ to whatever $site->url() returns on your live server. If it doesnt match that, it will get the staging class instead.
Since the url includes the protocol, this will not work, you would have to compare against the full url
@VIPStephan If you use different config files per environment, you could set a config option in each one:
e.g config.staging.mydomain.com.php
<?php
return [
//... other settings
'bodyClass' => 'staging',
];
in your template:
<?= option('bodyClass', 'defaultValue') ?>
defaultValue is optional and just meant as a placeholder for any value you want to set if option is not set.
Im not sure i understand there… $site->url() will return the string for the domain the sites running on. if its staging.livedomain.com it wont match livedomain.com.
I think my mistake was ommiting the http / www bit for brevity.
Oh, I didn’t think it’s that simple. Thanks much. 
Yes, that’s what I meant.
An alternative would be
<?= $_SERVER['HTTP_HOST'] === 'example.com' ? 'live' : 'staging' ?>
The config option comes without ternary operator or multiple if statements in case you have more than two environments.