title: How can I add a default value to a go text/template?
body: <p>I want to create a golang template with a default value that is used if a parameter is not supplied, but if I try to use the <code>or</code> function in my template,  it gives me this error:</p>
  
  <pre><code>template: t2:2:20: executing "t2" at &lt;index .table_name 0&gt;: error calling index: index of untyped nil
  </code></pre>
  
  <p>Here's an example of the code: <a href="https://play.golang.org/p/BwlpROrhm6" rel="noreferrer">https://play.golang.org/p/BwlpROrhm6</a></p>
  
  <pre><code>// text/template is a useful text generating tool.
  // Related examples: http://golang.org/pkg/text/template/#pkg-examples
  package main
  
  import (
      "fmt"
      "os"
      "text/template"
  )
  
  var fullParams = map[string][]string{
      "table_name": []string{"TableNameFromParameters"},
      "min":        []string{"100"},
      "max":        []string{"500"},
  }
  var minimalParams = map[string][]string{
      "min": []string{"100"},
      "max": []string{"500"},
  }
  
  func check(err error) {
      if err != nil {
          fmt.Print(err)
      }
  }
  
  func main() {
      // Define Template
      t := template.Must(template.New("t2").Parse(`
          {{$table_name := (index .table_name 0) or "DefaultTableName"}}
          Hello World!
          The table name is {{$table_name}}
      `))
      check(t.Execute(os.Stdout, fullParams))
      check(t.Execute(os.Stdout, minimalParams))
  }
  </code></pre>
  
  <p>Googling has pointed me towards an <code>isset</code> function in <a href="https://github.com/gohugoio/hugo" rel="noreferrer">hugo's template engine</a>, but I can't figure out how they implemented it, and I am not sure if it would even solve my problem. </p>