title: How do I get the last element of a slice in a golang template
body: <p>I can get the size of a slice in a template like this</p>
  
  <pre><code>{{$size := len .Things}}
  </code></pre>
  
  <p>And I can index a slice in a template like this:</p>
  
  <pre><code>{{index .Things 4}}
  </code></pre>
  
  <p>But </p>
  
  <pre><code>{{index .Things $size}}
  </code></pre>
  
  <p>gives an "out of range" error because indexing a slice is zero-based.</p>
  
  <p>Do I have do all the function defining things or is there arithmetic available I can use?</p>
  
  <hr>
  
  <p>I.e. how do I do this <a href="https://stackoverflow.com/a/22535888">https://stackoverflow.com/a/22535888</a> but in a golang template.</p>
  
  <p>Defining a minus function: <a href="https://stackoverflow.com/a/24838050/10245">https://stackoverflow.com/a/24838050/10245</a></p>