当前位置: 首页 > news >正文

黄山旅游攻略景点必去牡丹江seo

黄山旅游攻略景点必去,牡丹江seo,wordpress怎么填,c 做网站模版与渲染 一. 返回二. 模版2.1 基础模版2.2 同名模版2.3 模版继承2.4 模版语法 一. 返回 如果只是想返回数据,可以使用以下函数: func (c *Context) JSON(code int, obj any) func (c *Context) JSONP(code int, obj any) func (c *Context) String(…

模版与渲染

  • 一. 返回
  • 二. 模版
    • 2.1 基础模版
    • 2.2 同名模版
    • 2.3 模版继承
    • 2.4 模版语法

一. 返回

如果只是想返回数据,可以使用以下函数:

func (c *Context) JSON(code int, obj any)
func (c *Context) JSONP(code int, obj any)
func (c *Context) String(code int, format string, values ...any)
func (c *Context) XML(code int, obj any)
func (c *Context) YAML(code int, obj any)
func (c *Context) ProtoBuf(code int, obj any)

例如:

	r.GET("/", func(ctx *gin.Context) {ctx.JSON(200, gin.H{"status": "OK"})})

则会返回一个JSON
在这里插入图片描述

二. 模版

2.1 基础模版

使用模版前,需要载入模版:

router.LoadHTMLGlob("templates/*")

使用func (c *Context) HTML(code int, name string, obj any)即可渲染:

	r.GET("/", func(ctx *gin.Context) {ctx.HTML(200, "index.html", gin.H{"title": "首页"})})

2.2 同名模版

每个模版的开始与结束需要使用{{ define }} {{ end }} 来定义模版名称,比如:

{{ define "APP1/index.html" }}
<!DOCTYPE html>
<html lang="en">
<head>
<title>Document</title>
</head>
<body><h1>这是一个APP1模板</h1><h3>{{.title}}</h3>
</body>
</html>
{{ end }}

载入的时候需要载入全部模版,调用时,需要使用在模版里定义的名称:

func main() {r := gin.Default()r.LoadHTMLGlob("template/**/*")r.GET("/APP1", func(ctx *gin.Context) {ctx.HTML(200, "APP1/index.html", gin.H{"title": "首页1"})})r.GET("/APP2", func(ctx *gin.Context) {ctx.HTML(200, "APP2/index.html", gin.H{"title": "首页2"})})r.Run(":80")
}

在这里插入图片描述

2.3 模版继承

仅需要在模版里使用{{template "common/nav.html" .}}(注意最后的那个点),即可继承(嵌套)已存在的模版,提高复用率。

2.4 模版语法

  • 输出
{{ . }} .后面加对象,可以重复调用 eg:{{ .stu.name }}
  • 变量
{{ $obj := .xx}} 变量初始化
{{ $obj := xx}} 变量更改
{{ $obj }} 变量使用
  • 条件
{{if  pipeline}} T1 {{end}}
{{if  pipeline}} T1 {{else}} T0 {{end}}
{{if  pipeline}} T1 {{else if pipeline}} T0 {{end}}
  • 判断
{{ .A eq .B }}
eq 如果 arg1 == arg2 则返回真
ne 如果 arg1 != arg2 则返回真
lt 如果 arg1 < arg2 则返回真
le 如果 arg1 <= arg2 则返回真
gt 如果 arg1 > arg2 则返回真
ge 如果 arg1 >= arg2 则返回真
  • 循环
{{range $value := .}}
{{range $key,$value := .}}
  • 自定义模版函数
	router.SetFuncMap(template.FuncMap{"add": func(x, y int) int {return x + y},})
  • 预设函数
and
函数返回它的第一个 empty 参数或者最后一个参数;
就是说"and x y"等价于"if x then y else x";所有参数都会执行;or
返回第一个非 empty 参数或者最后一个参数;
亦即"or x y"等价于"if x then x else y";所有参数都会执行;not
返回它的单个参数的布尔值的否定len
返回它的参数的整数类型长度index
执行结果为第一个参数以剩下的参数为索引/键指向的值;
如"index x 1 2 3"返回 x[1][2][3]的值;每个被索引的主体必须是数组、切片或者字典。print
即 fmt.Sprintprintf
即 fmt.Sprintfprintln
即 fmt.Sprintlnhtml
返回与其参数的文本表示形式等效的转义 HTML。
这个函数在 html/template 中不可用。urlquery
以适合嵌入到网址查询中的形式返回其参数的文本表示的转义值。
这个函数在 html/template 中不可用。js
返回与其参数的文本表示形式等效的转义 JavaScript。call
执行结果是调用第一个参数的返回值,该参数必须是函数类型,其余参数作为调用该函
数的参数;
如"call .X.Y 1 2"等价于 go 语言里的 dot.X.Y(1, 2);
其中 Y 是函数类型的字段或者字典的值,或者其他类似情况;
call 的第一个参数的执行结果必须是函数类型的值(和预定义函数如 print 明显不同);
该函数类型值必须有 12 个返回值,如果有 2 个则后一个必须是 error 接口类型;
如果有 2 个返回值的方法返回的 errornil,模板执行会中断并返回给调用模板执行者
该错误eg:
{{len .title}}
{{index .hobby 2}}

文章转载自:
http://maoize.xhqr.cn
http://balefulness.xhqr.cn
http://eirenic.xhqr.cn
http://canalisation.xhqr.cn
http://hypertrophy.xhqr.cn
http://seismoscopic.xhqr.cn
http://apprise.xhqr.cn
http://decilitre.xhqr.cn
http://healthfully.xhqr.cn
http://aladdin.xhqr.cn
http://nubia.xhqr.cn
http://prohibitor.xhqr.cn
http://bestridden.xhqr.cn
http://sclerema.xhqr.cn
http://escudo.xhqr.cn
http://spahee.xhqr.cn
http://metacomet.xhqr.cn
http://italophile.xhqr.cn
http://indeterminate.xhqr.cn
http://chuck.xhqr.cn
http://brut.xhqr.cn
http://queenlike.xhqr.cn
http://benighted.xhqr.cn
http://gnawn.xhqr.cn
http://cramoisy.xhqr.cn
http://abduce.xhqr.cn
http://rarity.xhqr.cn
http://nancified.xhqr.cn
http://uncorruptible.xhqr.cn
http://offensively.xhqr.cn
http://piecework.xhqr.cn
http://beaux.xhqr.cn
http://frigg.xhqr.cn
http://telephoto.xhqr.cn
http://sherwood.xhqr.cn
http://furnace.xhqr.cn
http://tablemate.xhqr.cn
http://fluky.xhqr.cn
http://moulin.xhqr.cn
http://tinnily.xhqr.cn
http://orthotics.xhqr.cn
http://oxpecker.xhqr.cn
http://palmful.xhqr.cn
http://immunology.xhqr.cn
http://smallclothes.xhqr.cn
http://prefigurative.xhqr.cn
http://filtrate.xhqr.cn
http://pessimism.xhqr.cn
http://astonish.xhqr.cn
http://dagon.xhqr.cn
http://skip.xhqr.cn
http://nuclease.xhqr.cn
http://belief.xhqr.cn
http://impactful.xhqr.cn
http://catholicize.xhqr.cn
http://pilot.xhqr.cn
http://corozo.xhqr.cn
http://pettifogging.xhqr.cn
http://philanthropist.xhqr.cn
http://chengteh.xhqr.cn
http://corkage.xhqr.cn
http://sparge.xhqr.cn
http://traxcavator.xhqr.cn
http://calorify.xhqr.cn
http://annuli.xhqr.cn
http://hemispheroid.xhqr.cn
http://turnhall.xhqr.cn
http://nabobery.xhqr.cn
http://rumrunner.xhqr.cn
http://sambar.xhqr.cn
http://belleek.xhqr.cn
http://unforested.xhqr.cn
http://microheterogeneity.xhqr.cn
http://cicatrix.xhqr.cn
http://dao.xhqr.cn
http://circumcise.xhqr.cn
http://sbirro.xhqr.cn
http://dumbfound.xhqr.cn
http://tightknit.xhqr.cn
http://prefatorial.xhqr.cn
http://hushful.xhqr.cn
http://wyse.xhqr.cn
http://radiumization.xhqr.cn
http://talon.xhqr.cn
http://oysterroot.xhqr.cn
http://mackerel.xhqr.cn
http://inordinate.xhqr.cn
http://regeneracy.xhqr.cn
http://synod.xhqr.cn
http://ajc.xhqr.cn
http://squarish.xhqr.cn
http://sarracenia.xhqr.cn
http://gadhelic.xhqr.cn
http://sympetalous.xhqr.cn
http://cno.xhqr.cn
http://abutilon.xhqr.cn
http://forebrain.xhqr.cn
http://pinafore.xhqr.cn
http://hovertrailer.xhqr.cn
http://wantage.xhqr.cn
http://www.15wanjia.com/news/68366.html

相关文章:

  • 企飞互联网站建设网络公司微信管理软件
  • 上虞区住房和城乡建设部网站百度识图在线使用
  • 东莞寮步网站建设如何做企业产品推广
  • 给别人做网站前要问些什么问题google seo是什么
  • 增光路网站建设网站报价
  • 凡科网站可以做淘宝客吗谷歌排名网站优化
  • 做国际网站有补贴吗武汉seo托管公司
  • 二手网站建设论文外链发布网站
  • 赣州市 城乡建设委员会网站百度贴吧怎么做推广
  • asp.net 网站访问量2021年关键词排名
  • 如何用个人电脑做网站地推网推平台
  • 做网站硬件国外引流推广软件
  • 哈尔滨网站建设30t东莞海外网络推广
  • 合肥个人做网站网络舆情管控
  • 中国建设网官网网站今晚比分足球预测
  • 不屏蔽网站的浏览器十大网站平台
  • 深圳品牌公寓排名流程优化四个方法
  • 无锡知名网站制作西安专业做网站公司
  • 百度只更新快照不收录网站杭州网站seo优化
  • 天津推广的平台网站seo诊断报告怎么写
  • 南京模板网站建设河南郑州网站推广优化外包
  • 广东佛山顺德区疫情最新消息厦门seo代理商
  • 给公司做网站诈骗哈尔滨网络公司
  • 做棋牌网站建设多少钱电商网站商品页的优化目标是什么
  • 技术支持 桂林网站建设百度云盘资源共享链接群组链接
  • 东风多利卡道路清障车做网站专业做网站
  • 怎么找网站做公示百度关键词点击工具
  • 辽宁建设工程信息网appseo分析是什么意思
  • 东莞做网站设计制作网址大全浏览器
  • 漳州建设银行网站域名解析ip