title: Check if value exists in nested array with template package
body: <p>Using the <code>text/template</code>, I need to find out if any object in an array has a certain property value.</p>
  
  <p>Let's say I have a list of people (json):</p>
  
  <pre><code>[
      {"name": "ANisus", "sex":"M"},
      {"name": "Sofia", "sex":"F"},
      {"name": "Anna", "sex":"F"}
  ]
  </code></pre>
  
  <p>Using the template, I want to have this output:</p>
  
  <pre><code>Females:
  Sofia
  Anna
  </code></pre>
  
  <p>But the header, <code>Females:</code>, should only show in case there are actually any person with <code>sex</code> set to <code>F</code>. How can I perform this within the template system? My first attempt was by using a variable:</p>
  
  <pre><code>{{$hasFemale := 0}}
  {{range .}}{{if eq .sex "F"}}{{$hasFemale := 1}}{{end}}{{end}}
  {{if $hasFemale}}Female:{{end}}
  </code></pre>
  
  <p>I didn't get this to work because the $hasFemale within the range is in a different scope and not the same as the one initiated with 0. I can't seem to find a way to change a variable once it is initiated.</p>
  
  <p>"Working" example: <a href="http://play.golang.org/p/T-Ekx7n9YQ" rel="nofollow">http://play.golang.org/p/T-Ekx7n9YQ</a></p>
  
  <p>And I can not move this logic to the application; it must be done within the template.</p>