---
title: "Accessing Acquia's Environment Variables from a Twig Template"
date: "2022-03-08T00:11:42+00:00"
summary:
image:
type: "article"
url: "/acquia-cloud-platform/help/92636-accessing-acquias-environment-variables-twig-template"
id: "7d802497-ec85-4bd6-b7bc-3f3dd508a653"
---

You can expose [Acquia environment variables](/node/56164) to your Twig templates with a preprocess function using `getenv()`:

    /**
     * Implements template_preprocess_page().
     */
    function MYTHEME_preprocess_page(&$variables) {
      $variables['my_variable'] = getenv('AH_SITE_ENVIRONMENT');
    }

In this example, it adds the `{{ my_variable }}` Twig variable which contains the environment the Acquia site loads from.

Note that we are using `preprocess_page()` and the `AH_SITE_ENVIRONMENT` variable as examples. You would have to replace `MYTHEME` with your theme's name, and use the appropriate function and environment variable for your particular use case. [See the Drupal API documentation on preprocessing for template files](https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Render%21theme.api.php/group/themeable/8.9.x#sec_preprocess_templates) for more details.