Is it possible to change the scope of a variable in a range of Data items?
Here is my code
{{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?
No. You have to define the global variable before the range.
{{ $globalLoc := "" }}
{{range .Site.Data.country}}
{{ $globalLoc = .location }}
<option value="{{.location}}">{{.location}}</option>
{{end}}
{{ $globalLoc }}
See Introduction to Hugo Templating | Hugo .
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
You asked the same question 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.
erik06
April 12, 2021, 7:30pm
5
You would want to use JavaScript for this.