<p>Add them to <a href="https://craftcms.com/docs/config-settings#environmentVariables" rel="nofollow noreferrer">the <code>environmentVariables</code> section</a> of your config file, and retrieve them using <a href="https://craftcms.com/docs/templating/craft.config" rel="nofollow noreferrer">the <code>craft.config</code> template tag</a>.</p>

<p>For example:</p>

<pre><code>// Config 
"environmentVariables" =&gt; [
    "color" =&gt; "blue",
]

// Template
{{ craft.config.environmentVariables.color }}
</code></pre>

CC BY-SA 3.0
2017-04-15T22:24:30.390Z
Thanks for this. I was hoping for a more isolated solution (per template folder), but this will do fine as well.
tom
CC BY-SA 3.0
2017-04-15T22:26:24.107Z
You can create nested arrays in the environment variables array, to "scope" your variables..
Stephen Lewis
CC BY-SA 3.0
2017-04-11T16:32:48.567Z
2017-04-11T16:32:48.567Z
Stephen Lewis
<p>I have 4 main template folders, under the /craft folder (each template folder works for another subdomain). </p>

<p>Now, I do have per template folder, a few variables that I like to have shared amongst all templates underneath it.</p>

<p>Such as: </p>

<pre><code>{% set projectsGroup = "projectsWeather" %}
{% set sliderGroup = "sliderWeather" %}
{% set faqGroup = "faqWeather" %}
</code></pre>

<p>Which are different, per template folder.</p>

<p>Now, when I put these variables at the top of my master _layout file, this gets shared nicely amongst all templates -- that is, for those that use this _layout file. </p>

<p>I do however also have a few json generation template files, that can not use the _layout file. </p>

<p>My question now is how to elegantly assign these variables, and do this only once. </p>

<p>I can not stick them in a separate file and just use "include" or "extend", because then _layout either ignores or complains. </p>

<p>Any ideas?</p>

<templating><globals>
Globally share variables
# Globally share variables

(Asked by: username_0 on 2017-04-11)

I have 4 main template folders, under the /craft folder (each template folder works for another subdomain). 
Now, I do have per template folder, a few variables that I like to have shared amongst all templates underneath it.
Such as: 
{% set projectsGroup = "projectsWeather" %}
{% set sliderGroup = "sliderWeather" %}
{% set faqGroup = "faqWeather" %}

Which are different, per template folder.
Now, when I put these variables at the top of my master _layout file, this gets shared nicely amongst all templates -- that is, for those that use this _layout file. 
I do however also have a few json generation template files, that can not use the _layout file. 
My question now is how to elegantly assign these variables, and do this only once. 
I can not stick them in a separate file and just use "include" or "extend", because then _layout either ignores or complains. 
Any ideas?

**Tags:** templating, globals


---

## 1 answers

### Answer by username_1 on 2017-04-11. Score: 1 | Accepted answer

Add them to the environmentVariables section of your config file, and retrieve them using the craft.config template tag.
For example:
// Config 
"environmentVariables" => [
    "color" => "blue",
]

// Template
{{ craft.config.environmentVariables.color }}

> **Comments:**
> **username_0**: Thanks for this. I was hoping for a more isolated solution (per template folder), but this will do fine as well.  
> **username_1**: You can create nested arrays in the environment variables array, to "scope" your variables..  

---

