Twig usage with indicator

Created on 25 February 2020, about 5 years ago
Updated 13 May 2025, 11 days ago

It would be nice to use the module with twig.

{% if enviroment.local %}
 do something html locally
{% else %}
 everyhting for the live site
{% endif %}
✨ Feature request
Status

Closed: won't fix

Version

3.0

Component

Code

Created by

πŸ‡©πŸ‡ͺGermany stillworks

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States trackleft2 Tucson, AZ πŸ‡ΊπŸ‡Έ

    Interestingly enough, Environment Indicator module doesn't actually keep track of the environment it is on, nor does it have rules for getting that information.

    However, if you are working on a site with the environment indicators set up you should be able to use the environment information in a round-about way with something like twig_tweak β†’

    {{ drupal_config(config_name, key) }}

    {% set indicator = drupal_config('environment_indicator', 'indicator') %}
    
    {% if indicator.get('name') == 'Local Dev' %}
      <p>Show local something html locally</p>
    {% else %}
      <p>Everything for the live site</p>
    {% endif %}
    
    

    This is assuming you have something like this in your site's settings.php

      /**
       * Environment Indicator module settings.
       * see: https://pantheon.io/docs/environment-indicator
       */
      // Pantheon Env Specific Config
      if (isset($_ENV['PANTHEON_ENVIRONMENT'])) {
        switch ($_ENV['PANTHEON_ENVIRONMENT']) {
          case 'lando':
            // Localdev or Lando environments.
            $config['environment_indicator.indicator']['name'] = 'Local Dev';
            $config['environment_indicator.indicator']['bg_color'] = '#990055';
            break;
          case 'dev':
            $config['environment_indicator.indicator']['name'] = 'Dev';
            $config['environment_indicator.indicator']['bg_color'] = '#4a634e';
            break;
          case 'test':
            $config['environment_indicator.indicator']['name'] = 'Test';
            $config['environment_indicator.indicator']['bg_color'] = '#a95c42';
            break;
          case 'live':
            $config['environment_indicator.indicator']['name'] = 'LIVE';
            break;
          default:
            // Multidev catchall.
            $config['environment_indicator.indicator']['name'] = 'Multidev: ' . $_ENV['PANTHEON_ENVIRONMENT'];
            $config['environment_indicator.indicator']['bg_color'] = '#1e5288';
            break;
        }
      }
    }
    else {
      $config['environment_indicator.indicator']['name'] = 'Local';
      $config['environment_indicator.indicator']['bg_color'] = '#707070';
    }
    
Production build 0.71.5 2024