Skip to content

Instantly share code, notes, and snippets.

@blaskovicz
Created June 30, 2017 18:01
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save blaskovicz/981124737402a5407d110cf853977aaa to your computer and use it in GitHub Desktop.
Save blaskovicz/981124737402a5407d110cf853977aaa to your computer and use it in GitHub Desktop.
Golang template features (nested variables, range over array, index into map, conditionals)
<div class="levels">
{{ $groups := .LevelGroups }}
{{ $groupedLevels := .Levels }}
{{ $completeLevels := .CompleteLevels }}
{{ if $groupedLevels }}
{{ range $group := $groups }}
<div class="intro"><h2>{{$group}}</h2></div>
{{ range index $groupedLevels $group }}
<a href="/level/{{.Number}}" class="{{if index $completeLevels .Number}}complete{{end}}">
<span class="level">{{.Number}} </span>
{{.Title}}
<span class="mark-complete">¢</span>
</a>
{{end}}
<br />
{{ end }}
{{ end }}
</div>
@blaskovicz
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment