title: Using struct method in Golang template
body: <p>Struct methods in Go templates are usually called same way as public struct properties but in this case it just doesn't work: <a href="http://play.golang.org/p/xV86xwJnjA" rel="noreferrer">http://play.golang.org/p/xV86xwJnjA</a></p>
  
  <pre><code>{{with index . 0}}
    {{.FirstName}} {{.LastName}} is {{.SquareAge}} years old.
  {{end}}  
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code>executing "person" at &lt;.SquareAge&gt;: SquareAge is not a field
  of struct type main.Person
  </code></pre>
  
  <p>Same problem with:</p>
  
  <pre><code>{{$person := index . 0}}
  {{$person.FirstName}} {{$person.LastName}} is
    {{$person.SquareAge}} years old.
  </code></pre>
  
  <p>In constrast, this works:</p>
  
  <pre><code>{{range .}}
    {{.FirstName}} {{.LastName}} is {{.SquareAge}} years old.
  {{end}}
  </code></pre>
  
  <p>How to call SquareAge() method in {{with}} and {{$person}} examples?</p>