在这里插入图片描述
bar.html

bar: {{ .|lower }}

index.html

{{ .name }}

{{ if .body }}{{ else }}{{ end }}

{{ range .scores }}
{{.}}|
{{ end }}

<br/>
{{ range $index,$value := .scores }}
{{$index}} = {{$value}} <br />
{{ end }}


{{ range .users }}
{{ . }}
{{ end }}

{{ range $key, $value := .users }}
{{ $key }} = {{ $value }} <br/>
{{ end }}


{{ lower .content }}


{{ .content|lower }}

{{ define "lower" }}
输入内容: {{ .|lower }}
{{ end }}


{{ template "lower" .content }}
{{ template "lower" .content }}
{{ template "lower" .content }}
{{ template "lower" .content }}
{{ template "lower" .content }}
{{ template "lower" .content }}

<br />
{{ template "bar.html" .content}}
{{ template "bar.html" .content}}
{{ template "bar.html" .content}}
{{ template "bar.html" .content}}
{{ template "bar.html" .content}}

main.go

package main

import (
	"strings"

	"github.com/astaxie/beego"
)

type HomeController struct {
	beego.Controller
}

func (c *HomeController) Index() {
	c.Data["name"] = "kk"
	c.Data["body"] = true
	c.Data["scores"] = []float32{1, 2, 3, 4}
	c.Data["users"] = map[int]string{1: "kk", 2: "wc"}
	c.Data["content"] = "abc.ABC"
	c.TplName = "index.html" // 默认后缀只支持html, tpl
}

func (c *HomeController) Home() {
	// 若无任何响应,则加载控制器名称/Action名.tpl文件显示
}

func main() {

	beego.AddFuncMap("lower", func(in string) string {
		return strings.ToLower(in)
	})

	beego.AutoRouter(&HomeController{})
	beego.Run()
}
Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐