# Is staticDir2 available as a variable?

**URL:** <https://discourse.gohugo.io/t/is-staticdir2-available-as-a-variable/10689>\
**Category:** support\
**Created:** [February 23, 2018, 10:48am UTC](https://discourse.gohugo.io/t/is-staticdir2-available-as-a-variable/10689 "2018-02-23T10:48:22Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thierry](https://avatars.discourse-cdn.com/v4/letter/t/65b543/32.png) [@Thierry](https://discourse.gohugo.io/u/Thierry)\
**Post date:** [February 23, 2018, 10:48am UTC](https://discourse.gohugo.io/t/is-staticdir2-available-as-a-variable/10689/1 "2018-02-23T10:48:22Z")

</div>

I am using a 2nd static dir to store resources like bootstrap/jquery css and js files which can be used conditionally. The purpose is to have 2 different config.toml files, one for local development which uses this local version of the files (staticDir2 is defined with the path), and another config file for the live site which pulls the static resources from official CDNs (the staticDir2 variable is empty or omitted).

Testing on the existence/value of .Site.staticDir2 in the partials does not work:  
executing “theme/partials/header.html” at \<.Site.staticDir2\>: can’t evaluate field StaticDir in type \*hugolib.SiteInfo

Is there a way to check on this variable ? For the sake of simplicity of the config file, I’d like to avoid having to define another variable under ‘params’ to identify that staticDir2 is in use, if that is possible.

---

<div class="post-metadata">

**Author:** ![bep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bep/32/3332_2.png) [@bep](https://discourse.gohugo.io/u/bep)\
**Post date:** [February 23, 2018, 3:11pm UTC](https://discourse.gohugo.io/t/is-staticdir2-available-as-a-variable/10689/2 "2018-02-23T15:11:54Z")

</div>

> [@Thierry](#):
>
> Is there a way to check on this variable ?

No. But even if it was, it would have no value on its own. The static dirs configuration becomes a big union file system.

---

<div class="post-metadata">

**Author:** ![davidsneighbour](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/davidsneighbour/32/24507_2.png) [@davidsneighbour](https://discourse.gohugo.io/u/davidsneighbour)\
**Post date:** [February 25, 2018, 10:33am UTC](https://discourse.gohugo.io/t/is-staticdir2-available-as-a-variable/10689/3 "2018-02-25T10:33:27Z")

</div>

I think the following link on stackoverflow will give you a hint how to do this with javascript (it’s the other way around, using CDN and fall back local, but you get the drift). this will slow the page down if the fallback needs to run.

> <https://stackoverflow.com/questions/16077276/how-to-load-local-files-if-cdn-is-not-working>

Other than that a simple extra parameter `nocdn` in the config file will not kill simplicity and everyone downloading external libraries and putting them in the secondary static dir will have no problem to add this or uncomment this parameter. it’s probably best to assume people want to use the CDN unless they add a `nocdn` param in this constellation.

---

<div class="post-metadata">

**Author:** ![Thierry](https://avatars.discourse-cdn.com/v4/letter/t/65b543/32.png) [@Thierry](https://discourse.gohugo.io/u/Thierry)\
**Post date:** [February 25, 2018, 5:04pm UTC](https://discourse.gohugo.io/t/is-staticdir2-available-as-a-variable/10689/4 "2018-02-25T17:04:33Z")

</div>

Thanks for confirming that this variable cannot be checked on. Agreed that the value in itself is of no real use. I’ll fall back to using a custom variable under ‘params’ for my needs.

---

<div class="post-metadata">

**Author:** ![Thierry](https://avatars.discourse-cdn.com/v4/letter/t/65b543/32.png) [@Thierry](https://discourse.gohugo.io/u/Thierry)\
**Post date:** [February 25, 2018, 5:27pm UTC](https://discourse.gohugo.io/t/is-staticdir2-available-as-a-variable/10689/5 "2018-02-25T17:27:13Z")

</div>

Thanks pkollitsch for the link and suggestion. Your “fallback” scenario could be an option which I had not thought of. In the end, I’ll stick to the "extra parameter " way of doing it. CDNs are pretty reliable nowadays, at least those used by the usual suspects (bootstrap, jquery, font-awesome), so I am not sure I want to add a javascript-based fall back option in the code for the live site.

All I need really is for the development site for me to have the ability to work on it and test it locally even without being connected to the Internet in some cases as happens from time to time (CDN unreachable). Latency is also improved by having the files locally. For that, the extra parameter associated with an {{ if .noCDN }} check in footer.html and header.tml will be sufficient, and 2 config.toml files, one for dev with noCDN set to ‘true’ and staticDir2 defined, and one for the live site without them.

---

<div class="post-metadata">

**Author:** ![davidsneighbour](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/davidsneighbour/32/24507_2.png) [@davidsneighbour](https://discourse.gohugo.io/u/davidsneighbour)\
**Post date:** [February 26, 2018, 3:40am UTC](https://discourse.gohugo.io/t/is-staticdir2-available-as-a-variable/10689/6 "2018-02-26T03:40:09Z")

</div>

Have a look at @bep’s answer in this thread:

> [@How to check if the site is on localhost?](https://discourse.gohugo.io/t/how-to-check-if-the-site-is-on-localhost/1490):
>
> Hello, I’d like to add features to the theme that are only visible when the site is in the development environment (localhost). How can I do that? I thought about using the $.Site.BaseURL variable and checking if this variable equals or contains “localhost”. After all, this {{ printf "%#v" $.Site.BaseURL }} outputs… "http://localhost:1313/" But neither in nor eq seem to work with $.Site.BaseURL: {{ if in $.Site.BaseURL "localhost" }} localhost code, doesn't work {{ end }} and {{ if eq…

That should work without config variable if you need it only for local development.

---

<div class="post-metadata">

**Author:** ![Thierry](https://avatars.discourse-cdn.com/v4/letter/t/65b543/32.png) [@Thierry](https://discourse.gohugo.io/u/Thierry)\
**Post date:** [March 30, 2018, 1:39pm UTC](https://discourse.gohugo.io/t/is-staticdir2-available-as-a-variable/10689/7 "2018-03-30T13:39:44Z")

</div>

Thanks for the link to the other post. Very useful.

---

<div class="post-metadata">

**Author:** ![Jonathan\_Griffin](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jonathan_griffin/32/8355_2.png) [@Jonathan\_Griffin](https://discourse.gohugo.io/u/Jonathan_Griffin)\
**Post date:** [March 30, 2018, 1:43pm UTC](https://discourse.gohugo.io/t/is-staticdir2-available-as-a-variable/10689/8 "2018-03-30T13:43:24Z")

</div>

There is also:

```auto
.Site.IsServer

```

coming soon I believe - see [https://github.com/gohugoio/hugo/pull/4541](https://github.com/gohugoio/hugo/pull/4541)

For example:

```auto
{{if .Site.IsServer}}
Code here
{{end}}

```
