title: slice func not working in text/template in go
body: <p>this is my template code snippet</p>
  
  <pre><code>                     {{ if eq .Method "GET" -}}
                              {{ if eq (slice .SummeryAsComment 7 10) "all"}}
                                  getall(w,r)
                              {{ else }}
                                  getbyid(w,r)
                              {{ end }}
                        {{- end}}
  </code></pre>
  
  <p>running this gives me the following error.</p>
  
  <blockquote>
    <p>error generating code: error parsing user-provided template
    "chi-handler.tmpl": template: chi-handler.tmpl:123: function "slice"
    not defined</p>
  </blockquote>
  
  <p>But I checked it is one of the predefined function <a href="https://golang.org/pkg/text/template/" rel="nofollow noreferrer">available</a></p>
  
  <blockquote>
    <p>slice </p>
    
    <p>slice returns the result of slicing its first argument by the
      remaining arguments. Thus "slice x 1 2" is, in Go syntax, x[1:2],
      while "slice x" is x[:], "slice x 1" is x[1:], and "slice x 1 2 3"
      is x[1:2:3]. The first argument must be a string, slice, or array.</p>
  </blockquote>
  
  <p>So why is this not working? 
  I am actually editing a few templates provided by oapi-codegen <a href="https://github.com/deepmap/oapi-codegen" rel="nofollow noreferrer">repo</a>. But this should work there too. Shouldn't it?</p>
  
  <p>EDIT:
  Changing version didn't work.</p>
  
  <pre><code>go version
  go version go1.14.3 linux/amd64
  </code></pre>
  
  <p>I would like to explain what I am doing.</p>
  
  <p>I am working with openAPI to generate a server-code boilerplate. So the templates are provided in that oapi codegen repo above. But I don't want the exact boilerplate code so I need to change the templates. The steps for changing code is provided <a href="https://github.com/deepmap/oapi-codegen#making-changes-to-code-generation" rel="nofollow noreferrer">here</a>. More specifically I am doing the following.</p>
  
  <blockquote>
    <p>Alternatively, you can provide custom templates to override built-in
    ones using the -templates flag specifying a path to a directory
    containing templates files. These files must be named identically to
    built-in template files (see pkg/codegen/templates/*.tmpl in the
    source code), and will be interpreted on-the-fly at run time. </p>
  </blockquote>
  
  <p>I am running these commands after i have my templates ready:</p>
  
  <pre><code>$ go get github.com/deepmap/oapi-codegen/cmd/oapi-codegen
  $ oapi-codegen \
      -templates my-templates/ \
      -generate types,server \
      example-expanded.yaml  
  </code></pre>
  
  <p><em>my-templates</em> contains the templates I have changed. This <a href="https://github.com/deepmap/oapi-codegen/tree/master/pkg/codegen/templates" rel="nofollow noreferrer">dir</a> contains all the templates and I am changing a few of them and followed the steps as directed here.</p>