मुझे व्हाइटस्पेस को नियंत्रित करने में समस्या हो रही है और अभी भी एक पठनीय फैशन में html/template
टेम्पलेट्स स्वरूपित कर रहा है। मेरे टेम्पलेट्स इस तरह somthing देखने:एचटीएमएल/टेम्पलेट में किसी कार्रवाई के बाद मैं व्हाइटस्पेस को कैसे नियंत्रित कर सकता हूं?
layout.tmpl
{{define "layout"}}
<!DOCTYPE html>
<html>
<head>
<title>{{.title}}</title>
</head>
<body>
{{ template "body" . }}
</body>
</html>
{{end}}
body.tmpl
{{define "body"}}
{{ range .items }}
{{.count}} items are made of {{.material}}
{{end}}
{{end}}
कोड
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",
},
},
})
}
लेकिन वह पैदा करता है (ध्यान दें: वहाँ एक रेखा से ऊपर है डॉक्टरेट):
<!DOCTYPE html>
<html>
<head>
<title>stock</title>
</head>
<body>
2 items are made of angora
3 items are made of wool
</body>
</html>
क्या मैं चाहता हूँ है:
<!DOCTYPE html>
<html>
<head>
<title>stock</title>
</head>
<body>
2 items are made of angora
3 items are made of wool
</body>
</html>
अन्य टेम्पलेट भाषाओं में मैं कह सकता हूँ की तरह
[[- value -]]
और पहले और कार्रवाई के बाद खाली स्थान के बातें छीन रहे हैं, लेकिन मैं कुछ भी नहीं दिख रहा है जैसे में। क्या इसका वास्तव में मतलब है कि मुझे अपने टेम्पलेट्स को निम्नलिखित की तरह अपठनीय बनाना है?
layout.tmpl
{{define "layout"}}<!DOCTYPE html>
<html>
<head>
<title>.title</title>
</head>
<body>
{{ template "body" . }} </body>
</html>
{{end}}
body.tmpl
{{define "body"}}{{ range .items }}{{.count}} items are made of {{.material}}
{{end}}{{end}}
उपयोग कर सकते हैं के बाद से जाओ '1.6' https://golang.org/doc/go1.6#template – webwurst
हाँ, 1.6 से पहले @webwurst धन्यवाद आप https जाँच कर सकते हैं : //golang.org/pkg/text/template/#hdr-Text_and_spaces – hkulekci
यह केवल 'टेक्स्ट/टेम्पलेट' के लिए काम करता है, न कि 'html/template'। –