default.go
- package controllers
-
- import (
- "github.com/astaxie/beego"
- )
-
- type MainController struct {
- beego.Controller
- }
-
- func (c *MainController) Get() {
- c.Data["Website"] = "beego.me"
- c.Data["Email"] = "astaxie@gmail.com"
- c.TplName = "index.tpl"
-
- c.Data["TrueCond"] = true
- c.Data["FalseCond"] = false
-
- type u struct {
- Name string
- Age int
- Sex string
- }
-
- user := &u{
- Name: "Joe",
- Age: 20,
- Sex: "Male",
- }
-
- c.Data["User"] = user
-
- nums := []int{1,2,3,4,5,6,7,8,9,0}
- c.Data["Nums"] = nums
-
- c.Data["TplVar"] = "hey gays"
-
- c.Data["Html"] = "<div>Hello beego</div>"
-
- c.Data["Pipe"] = "<div>Hello beego</div>"
- }
index.tpl
- <body>
- <header>
- <div class="description">
- Beego is a simple & powerful Go web framework which is inspired by tornado and sinatra.
- </div>
- <div>
- {{if .TrueCond}}
- true condition
- {{end}}
- </div>
- <div>
- {{if .FalseCond}}
- {{else}}
- false condition
- {{end}}
- </div>
- <div>
- {{with .User}}
- {{.Name}}; {{.Age}}; {{.Sex}}
- {{end}}
- </div>
- <div>
- {{range .Nums}}
- {{.}}
- {{end}}
- </div>
- <div>
- {{$tplVar := .TplVar}}
- {{$tplVar}}
- </div>
- <div>
- {{str2html .Html}}
- </div>
- <div>
- {{.Pipe | htmlquote}}
- </div>
- <div>
- {{template "test"}}
- </div>
- </header>
- <footer>
- <div class="author">
- Official website:
- Contact me:
- </div>
- </footer>
-
- </body>
-
-
- {{define "test"}}
- <div>
- this is test template
- </div>
- {{end}}