title: Joining quoted, comma-separated strings (given a list of structs containing those strings)
body: <p>Using go templates, I've been trying to render a list of quoted, comma-separated strings</p>
  
  <p>e.g. <code>"string1", "string2", "string3"</code></p>
  
  <p>The strings I want to render come from a slice of structs. See the <code>Tags</code> in this example:</p>
  
  <pre><code>package main
  
  import (
      "fmt"
      "log"
      "os"
      "strings"
      "text/template"
  )
  
  const (
      templateString = `{{range .Tags}}"{{.Name}}", {{end}}`
  )
  
  var (
      funcs = template.FuncMap{
          "join":  strings.Join,
          "quote": func(in string) string { return fmt.Sprintf("\"%s\"", in) },
      }
      renderData = Task{
          Name:        "something to do",
          Description: "Do that thing",
          Tags: &amp;[]Tag{
              Tag{Name: "tag1"},
              Tag{Name: "tag2"},
          },
      }
  )
  
  func main() {
      tmpl, err := template.New("master").Funcs(funcs).Parse(templateString)
      if err != nil {
          log.Fatal(err)
      }
  
      if err := tmpl.Execute(os.Stdout, renderData); err != nil {
          log.Fatal(err)
      }
  
  }
  
  type Task struct {
      Name        string
      Description string
      Tags        *[]Tag
  }
  
  type Tag struct {
      Name string
  }
  </code></pre>
  
  <p><a href="https://goplay.space/#g8mT5adDNsz" rel="nofollow noreferrer">See it in the playground</a></p>
  
  <p>How could this be done, given the following constraint ? :</p>
  
  <ul>
  <li>I shouldn't add any too specific template function (e.g. one that joins and quotes <code>.Name</code>s for <code>Tag</code>s) (because my users will only be able to edit templates, not Go-code/template-functions, I should try and solve the problem with the same tools, which means templates and maybe very generic functions)</li>
  </ul>