In Jinja2 (Python Flask) templates, I'm able to create a static navigation menu by defining a list of tuples with code similar to the following:
{% for item in [('', 'Home'), ('menu1', 'Menu1'), ('menu2', 'Menu2')] %}
<li><a href="{% if item[0] == '' %}/{% else %}{{ '/%s/' % item[0] }}{% endif %}">{{ item[1] }}</a></li>
{%- endfor %}
I'd like to create something similar in Go HTML templates. I assume the equivalent to a list of tuples would be an array/slice of arrays of strings, i.e., something like
{{ $items := { {"", "Home"}, {"menu1", "Menu1"}, {"menu2", "Menu2"} } }}
{{ range $items }}
<li><a href="{{if .[0] == \"\"}}/{{else}}{{ \"/.[0]/\" }}{{end}}">{{ .[1] }}</a></li>
{{end}}
However, at runtime, specifically when Go tries to parse the template files it panics with unexpected "{" in command
(it used to panic with unexpected "{" in range
when I used a range directly).
So, is it possible to declare an array of arrays of strings in a template?