# Query Data items

**URL:** <https://discourse.gohugo.io/t/query-data-items/32335>\
**Category:** support\
**Created:** [April 12, 2021, 6:37pm UTC](https://discourse.gohugo.io/t/query-data-items/32335 "2021-04-12T18:37:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ddanawoski](https://avatars.discourse-cdn.com/v4/letter/d/edb3f5/32.png) [@ddanawoski](https://discourse.gohugo.io/u/ddanawoski)\
**Post date:** [April 12, 2021, 6:37pm UTC](https://discourse.gohugo.io/t/query-data-items/32335/1 "2021-04-12T18:37:14Z")

</div>

Is it possible to change the scope of a variable in a range of Data items?  
Here is my code

```auto
{{range .Site.Data.country}}
      <option value="{{.location}}">{{.location}}</option>
{{end}}

```

I want to be able to make .location a global variable scope.

I want to create an if statement out of the .location on a different range of data. Is this possible?

---

<div class="post-metadata">

**Author:** ![moorereason](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/moorereason/32/592_2.png) [@moorereason](https://discourse.gohugo.io/u/moorereason)\
**Post date:** [April 12, 2021, 6:56pm UTC](https://discourse.gohugo.io/t/query-data-items/32335/2 "2021-04-12T18:56:07Z")

</div>

> [@ddanawoski](#):
>
> Is it possible to change the scope of a variable in a range of Data items?

No. You have to define the global variable before the range.

```auto
{{ $globalLoc := "" }}
{{range .Site.Data.country}}
      {{ $globalLoc = .location }}
      <option value="{{.location}}">{{.location}}</option>
{{end}}
{{ $globalLoc }}

```

See [Templating | Hugo](https://gohugo.io/templates/introduction/#variables).

---

<div class="post-metadata">

**Author:** ![ddanawoski](https://avatars.discourse-cdn.com/v4/letter/d/edb3f5/32.png) [@ddanawoski](https://discourse.gohugo.io/u/ddanawoski)\
**Post date:** [April 12, 2021, 7:01pm UTC](https://discourse.gohugo.io/t/query-data-items/32335/3 "2021-04-12T19:01:38Z")

</div>

Thank you.

I want to be able to pick the value location from the option value in .Site.Data.country.  
How do I have that?

Something like this.  
if .location in .Site.Data.country is selected .ie value = to Books

Then have the disable attribute on some other form input true if not it should show up

---

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [April 12, 2021, 7:22pm UTC](https://discourse.gohugo.io/t/query-data-items/32335/4 "2021-04-12T19:22:58Z")

</div>

You [asked the same question](https://discourse.gohugo.io/t/query-data-items/31726) a month ago, and my guidance has not changed:

> It seems like you want to create an HTML form with a dependent dropdown, which is “off topic” for this forum. You might start by searching Stack Overflow.

---

<div class="post-metadata">

**Author:** ![erik06](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/erik06/32/12906_2.png) [@erik06](https://discourse.gohugo.io/u/erik06)\
**Post date:** [April 12, 2021, 7:30pm UTC](https://discourse.gohugo.io/t/query-data-items/32335/5 "2021-04-12T19:30:09Z")

</div>

> [@ddanawoski](#):
>
> ave the disable attribute on some other form input true if not it should sho

You would want to use JavaScript for this.
