Beego-View设计-基础函数

|  : 传递参数

在tpl中     {{.price | printf "%.2f" }}   做格式化取小数点后2位

结果  123.46


call :调用函数

在tpl中    {{call .function .x .y}}

结果    5


and : 取第一个空值,如果全部非空,就取最后一个非空值

在tpl中   {{and .x .y .z}}

结果:false

模板中的空值

  • false ,0
  • 指针类型的0:nil
  • interface
  • 长度为0的array,slice,map,string

index :

  • map的键是int类型

结果:   Tom

  • map的键是string类型,要加  " "

   取出键值为2的值

结果 : Tom


not :取反

通过not对数字取反,只有0为true,其他都是false

在tpl     {{not .flag1}}

             {{not .flag2}}

             {{not .num1}}

             {{not .num2}}

结果 :  false true false true


运算符 :<    >     <=    >=   ==   !=

结果:  100小于200

猜你喜欢

转载自blog.csdn.net/super_lixiang/article/details/82227101