2
私はゴランではかなり新しいです。ここでテンプレートレンダリングの結果を得る方法
は私の問題である:ここに私のコードであり、それはいないようだ私はtemplate.Executeの文字列の結果を取得したい、と私はhttp.ResponsWriter
に直接それを実行する必要はありませんうまく
package main
import (
"fmt"
"os"
"template"
)
type ByteSlice []byte
func (p *ByteSlice) Write(data []byte) (lenght int, err os.Error) {
*p = data
return len(data), nil
}
func main() {
page := map[string]string{"Title": "Test Text"}
tpl, _ := template.ParseFile("test.html")
var b ByteSlice
tpl.Execute(&b, &page)
fmt.Printf(`"html":%s`, b)
}
そしてtext.html動作するように:
<html>
<body>
<h1>{{.Title|html}}</h1>
</body>
</html>
をしかし、私が得たものは
です"html":</h1>
</body>
</html>