# Variable not globally nested, variable cannot be applied with if func

**URL:** <https://discourse.gohugo.io/t/variable-not-globally-nested-variable-cannot-be-applied-with-if-func/13449>\
**Category:** support\
**Created:** [August 8, 2018, 2:54pm UTC](https://discourse.gohugo.io/t/variable-not-globally-nested-variable-cannot-be-applied-with-if-func/13449 "2018-08-08T14:54:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![onlinemantas](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/onlinemantas/32/8837_2.png) [@onlinemantas](https://discourse.gohugo.io/u/onlinemantas)\
**Post date:** [August 8, 2018, 2:54pm UTC](https://discourse.gohugo.io/t/variable-not-globally-nested-variable-cannot-be-applied-with-if-func/13449/1 "2018-08-08T14:54:08Z")

</div>

Why is $lang not globally nested?

```
{{ $langVar := index .Site.Data.lang .Site.LanguageCode }}
{{ if eq $langVar “” }}
  {{ $lang := index .Site.Data.lang .Site.LanguageCode }}
{{ else }}
  {{ $lang := index .Site.Data.lang “en” }}
{{ end }}
```

---

<div class="post-metadata">

**Author:** ![pointyfar](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/pointyfar/32/5797_2.png) [@pointyfar](https://discourse.gohugo.io/u/pointyfar)\
**Post date:** [August 9, 2018, 2:31am UTC](https://discourse.gohugo.io/t/variable-not-globally-nested-variable-cannot-be-applied-with-if-func/13449/2 "2018-08-09T02:31:40Z")

</div>

> [@onlinemantas](#):
>
> Why is $lang not globally nested?

It’s a Go thing: [Hugo + Go 1.11 hype thread](https://discourse.gohugo.io/t/hugo-go-1-11-hype-thread/13198)

This recent post might help: [Scoping a variable outside of and if statement (or two)](https://discourse.gohugo.io/t/solved-scoping-a-variable-outside-of-and-if-statement-or-two/13229)

For now you will have to use `.Scratch` [Scratch | Hugo](https://gohugo.io/functions/scratch/)
