topshelfcraft/environment-label

...so you don't forget where you are.

4.0.3 2023-04-26 02:25 UTC

This package is auto-updated.

Last update: 2024-04-26 04:35:47 UTC


README

...so you don't forget where you are.

A Top Shelf Craft creation
in collaboration with Kind

TL;DR.

The Environment Label plugin adds a nice coloured banner to your CraftCMS control panel so you'll never forget what environment you're using.

The colors and text of the environment label are configurable via the plugin config file.

Screenshot

Installation

Visit the Plugin Store in your Craft control panel, search for Environment Label, and click to Install the plugin.

You can also install the package via Composer.

composer require topshelfcraft/environment-label

Then, navigate to the Plugins section of the control panel, find Environment Label in the list, and click the Install button.

Configuration

By default, the environment label will display the value of Craft's CRAFT_ENVIRONMENT constant, which is usually set to the current hostname unless you override it.

(In other words, out of the box, you get a red banner with white text that alerts you to the current hostname.)

You can use a plugin config file to tweak the appearance and text of the environment label for each installation.

Simply add an environment-label.php file to your config directory.

<?php

return [
    'showLabel' => true,
    'labelText' => CRAFT_ENVIRONMENT,
    'prefixText' => null,
    'suffixText' => null,
    'labelColor' => '#cc5643',
    'textColor' => '#ffffff',
    'targetSelector' => '#global-header:before',
];

For added flexibility, the full text of the label will be rendered as a Twig template, so you can also include template variables if you want:

<?php

return [
    'suffixText' => " // {{ currentUser }}",
);

Settings in the Control Panel

You can also make basic changes to the text and appearance of the environment label via the plugin Settings page.

Settings

This is provided as a convenience for easily testing out the plugin, but for full customizability, you should use a plugin config file as described above.

(Settings specified in the plugin config file will override any changes made via the Settings page in the control panel.)

Twig template globals

Environment Label makes its properties available via a Twig template global variable, so you can create your own environment label rendering in your public templates:

{{ environmentLabel.renderedText }}
{{ environmentLabel.labelColor }}
{{ environmentLabel.textColor }}

JavaScript globals

Environment Label also makes its properties available as JS globals on each authenticated CP page.

window.CRAFT_ENVIRONMENT
window.CRAFT_ENVIRONMENT_LABEL

What are the system requirements?

Craft 4.0+ and PHP 8.0.2+

I've found a bug.

No you haven't.

Yes, I believe I have.

Well, alright. Please open a GitHub Issue, and if you're feeling ambitious, submit a PR to the 4.x.dev branch.

Contributors: