beego 模板语法

参考网站

https://beego.me/docs/mvc/view/tutorial.md
controller 内容
this.Data["IsLogin"] = true
this.Data["IsHome"] = true
this.Data["IsAbout"] = true
this.Data["Name"] = "victor"
this.Data["Age"] = 20
if … end
      {{if .IsHome}}    
            如果存在 Ishome打印 1313113131
      {{end}}
     
if … else … end
      {{if .Isme}}    
            如果存在 Isme打印 1313113131
      {{else}}
            如果不存在 Isme打印 233333
      {{end}}
支持嵌套的循环
      {{if .Name}}
            打印名称{{.Name}}
      {{else}}
            {{if .Age}}
                  继续判断年龄,存在打印 {{.Age}}
            {{end}}
      {{end}}
也可以使用 else if 进行
      {{if .Name1}}
          打印名称{{.Name}}
      {{else if .Age1}}  
            继续判断年龄,存在打印 {{.Age}}
      {{else}}
            名字年龄都不存在
      {{end}}

eq / ne / lt / le / gt / ge

这类函数一般配合在 if 中使用

eq: arg1 == arg2
ne: arg1 != arg2
lt: arg1 < arg2
le: arg1 <= arg2
gt: arg1 > arg2
ge: arg1 >= arg2

eq 和其他函数不一样的地方是,支持多个参数,和下面的逻辑判断相同

arg1==arg2 || arg1==arg3 || arg1==arg4 ...
与 if 一起使用
{{if eq true .Var1 .Var2 .Var3}}{{end}}
range … end
controller 配置
	nums := []int{1,2,3,4,5,6,7,8,9}
	c.Data["Nums"] = nums


# html文件
      {{range .Nums}}
            {{.}}
      {{end}}
with end使用
# controller配置
type Person1 struct {
	Name string
	Age	int
}
	data := &Person1{"Ccg", 18}
	c.Data["Person1"] = data
	
	
# html文件	
      {{with .Person1}}
      {{.Name}}; {{.Age}}
      {{end}}

      等同于
      {{.Person1.Name}}; {{.Person1.Age}}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值