title: How can I control whitespace after an action in html/template?
body: <p>I am having a problem controlling whitespace and still formatting <code>html/template</code> templates in a readable fashion.  My templates look somthing like this:</p>
  
  <p>layout.tmpl</p>
  
  <pre><code>{{define "layout"}}
  &lt;!DOCTYPE html&gt;
  &lt;html&gt;
          &lt;head&gt;
                  &lt;title&gt;{{.title}}&lt;/title&gt;
          &lt;/head&gt;
          &lt;body&gt;
                  {{ template "body" . }}
          &lt;/body&gt;
  &lt;/html&gt;
  {{end}}
  </code></pre>
  
  <p>body.tmpl</p>
  
  <pre><code>{{define "body"}}
  {{ range .items }}
  {{.count}} items are made of {{.material}}
  {{end}}
  {{end}}
  </code></pre>
  
  <p>code</p>
  
  <pre><code>package main
  
  import (
      "os"
      "text/template"
  )
  
  type View struct {
      layout string
      body   string
  }
  
  type Smap map[string]string
  
  func (self View) Render(data map[string]interface{}) {
      layout := self.layout + ".tmpl"
      body   := self.body + ".tmpl"
      tmpl   := template.Must(template.New("layout").ParseFiles(layout, body))
      tmpl.ExecuteTemplate(os.Stdout, "layout", data)
  }
  
  func main() {
      view := View{ "layout", "body" }
      view.Render(map[string]interface{}{
          "title": "stock",
          "items": []Smap{
              Smap{
                  "count":    "2",
                  "material": "angora",
              },
              Smap{
                  "count":    "3",
                  "material": "wool",
              },
          },
      })
  }
  </code></pre>
  
  <p>But that produces (note: there is a line above the doctype):</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;title&gt;stock&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
  
  
  2 items are made of angora
  
  3 items are made of wool
  
  
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>What I want is:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;title&gt;stock&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
  2 items are made of angora
  3 items are made of wool
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>In other template languages I can say things like</p>
  
  <pre><code>[[- value -]]
  </code></pre>
  
  <p>and the whitespace before and after the action are stripped, but I don't see anything like that in <code>html/template</code>.  Does this really mean I have to make my templates unreadable like the following?</p>
  
  <p>layout.tmpl</p>
  
  <pre><code>{{define "layout"}}&lt;!DOCTYPE html&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;title&gt;.title&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
  {{ template "body" . }} &lt;/body&gt;
  &lt;/html&gt;
  {{end}}
  </code></pre>
  
  <p>body.tmpl</p>
  
  <pre><code>{{define "body"}}{{ range .items }}{{.count}} items are made of {{.material}}
  {{end}}{{end}}
  </code></pre>