February 2, 2015

Golang html/template range: access out of loop variable

When you use range in a Golang html/template the "." variable changes to the current object from the range. We can however still access to old "." variable with "$":

{{range $index, $emp := .employees}}
  {{ $emp.name }}
  {{ msg $ "btn_show" }}
{{ end }}

Leave a Reply

Your email address will not be published. Required fields are marked *

XFerion Europe LLP
We build an maintain your software. From web to mobile. From MVP to extended product. Contact us if you wish to discuss a project.