Пример #1
0
func hoisieMustache() {

	var sampleTemplate = `

## 表示
{{Title}}

## 変数の代入
分からなかった...

## for文
{{#FooList}}
{{.}}
{{/FooList}}

## mapのfor文
分からなかった...

## templateの入れ子
{{{content}}}
`

	var sampleFooterTemplate = `
> 子要素への変数渡し {{Title}}`

	text := mustache.RenderInLayout(sampleFooterTemplate, sampleTemplate, templateData)
	fmt.Println(text)
}
Пример #2
0
func indexHandler(w http.ResponseWriter, r *http.Request) {
	var data struct {
		Notes []Note
	}
	data.Notes = notes
	rendered := mustache.RenderInLayout(homeMarkup, loadTemplate("home"), data)
	fmt.Fprintf(w, rendered)
}
Пример #3
0
func noteHandler(w http.ResponseWriter, r *http.Request) {
	title := strings.Replace(r.URL.Path[lenPath:], ".html", "", -1)
	var rendered string
	for _, note := range notes {
		if note.Url == title {
			rendered = mustache.RenderInLayout(note.Body, loadTemplate("note"), note)
		}
	}
	if len(rendered) == 0 {
		fmt.Fprintf(w, "404 page not found")
	}
	fmt.Fprintf(w, rendered)
}