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

南京网站定制公司北京百度seo点击器

南京网站定制公司,北京百度seo点击器,汽车网有哪些网站大全,长沙建设网站Gin模板语法 文章目录 <center> Gin模板语法前提提醒Gin框架启动服务器模板解析模板渲染遇到不同目录下相同的文件如何加载和渲染自定义函数加载静态文件 前提提醒 由于有了前面template包的基础,所以该笔记不再过多详细分析 Gin框架启动服务器 语法: r:gin.Default()/…

Gin模板语法

文章目录

  • <center> Gin模板语法
    • 前提提醒
      • Gin框架启动服务器
      • 模板解析
      • 模板渲染
      • 遇到不同目录下相同的文件如何加载和渲染
      • 自定义函数
      • 加载静态文件

前提提醒

  • 由于有了前面template包的基础,所以该笔记不再过多详细分析

Gin框架启动服务器

  • 语法:
    • r:=gin.Default()//获取一个Engine变量
    • r.Get("网站路径",handleFunc...)//Get请求
    • r.Run(addr ...string)//启动服务器

模板解析

  • 语法:
    • r.LoadHTMLFiles(...filename)
    • r.LoadHTMLGlob("./ginTemplates/**/*")(正则表达式解析所有文件,"**"代表表示任意层级子目录, *代表任意文件

模板渲染

  • 语法:

    • r.Get("网站路径",handleFunc...)

    • 例子

      r.GET("/posts/index", func(c *gin.Context) {c.HTML(http.StatusOK, "posts/index.tmpl", gin.H{"title": "欢迎来到POSTS世界","url":   "<a href = 'http://localhost:9000/users/index'>USER世界</a>",})})
      

遇到不同目录下相同的文件如何加载和渲染

  • 方法: 在tmpl模板中用define关键字定义名字,再解析

  • 例子:

    {{/*通过定义名字区分不同目录下相同文件名的文件渲染和解析*/}}
    {{define "posts/index.tmpl"}}//<----主要是这里
    <!DOCTYPE html>
    <html lang="en">
    <head><meta charset="UTF-8">{{/*加载css静态文件需要在头部连接*/}}<link  rel="stylesheet" href="/xxx/index.css"><title>Gin模板渲染</title>
    </head>
    <body>
    <script src = "/xxx/index.js"></script>
    <h1>{{.title}}</h1>
    <p>{{.url | safe}}</p>
    <p>{{hello}}</p>
    </body>
    </html>
    {{end}}
    

自定义函数

  • 语法:

    • r.SetFuncMap(funcMap template.FuncMap)//其内部包装的是 template.FuncMap,所以原理一样
  • 注意:需要在模板解析前添加自定义函数

  • 例子

    	r.SetFuncMap(template.FuncMap{"safe": func(str string) template.HTML {return template.HTML(str) //强转},"hello": func() string {return "hello"},})
    
  • 用法:

    • 像是safe这种可以传参的,可以通过"|"符号应用到某个字符中

    • 例子:

      //tmpl
      <p>{{.url | safe}}</p>//后端
      r.GET("/posts/index", func(c *gin.Context) {c.HTML(http.StatusOK, "posts/index.tmpl", gin.H{"title": "欢迎来到POSTS世界","url":   "<a href = 'http://localhost:9000/users/index'>USER世界</a>",})})
      
      • 这里的url会被转义为template.HTML类型输出到网页中
    • hello这种只是传文字的可以直接使用

    • 例子:

      //tmpl
      <p>{{hello}}</p>//后端
      r.GET("/posts/index", func(c *gin.Context) {c.HTML(http.StatusOK, "posts/index.tmpl", gin.H{"title": "欢迎来到POSTS世界","url":   "<a href = 'http://localhost:9000/users/index'>USER世界</a>",})})
      

加载静态文件

  • 语法: r.Static(参数1,参数2)

    • 第一个参数"/xxx"表示在请求URL中使用的访问前缀。
      第二个参数:为实际文件所在目录的路径*/
      
  • 使用

    • css中演示(其他基本一致)

    • 例子:

      <link  rel="stylesheet" href="/xxx/index.css">//后端
      r.Static("/xxx", "./statics")
      
      • 这里的/xxx是请求URL中使用的访问前缀
      • ./statics为文件目录的路径
      • /index.css为目标文件的路径

文章转载自:
http://dinncometacode.wbqt.cn
http://dinncoinformation.wbqt.cn
http://dinncoairspace.wbqt.cn
http://dinncoclouet.wbqt.cn
http://dinncodean.wbqt.cn
http://dinncomasturbatory.wbqt.cn
http://dinncoanglofrisian.wbqt.cn
http://dinncosoever.wbqt.cn
http://dinncoslopwork.wbqt.cn
http://dinncogranitic.wbqt.cn
http://dinncowholesale.wbqt.cn
http://dinncopigsticking.wbqt.cn
http://dinncoisotonic.wbqt.cn
http://dinncokeramic.wbqt.cn
http://dinncomonarchic.wbqt.cn
http://dinncoconvertibility.wbqt.cn
http://dinncotoile.wbqt.cn
http://dinncodecrescendo.wbqt.cn
http://dinncounattached.wbqt.cn
http://dinncocampania.wbqt.cn
http://dinncopyroceram.wbqt.cn
http://dinncohighbinding.wbqt.cn
http://dinncoportreeve.wbqt.cn
http://dinncoyardwand.wbqt.cn
http://dinncocontagion.wbqt.cn
http://dinncopentobarbital.wbqt.cn
http://dinncowaadt.wbqt.cn
http://dinncocheckpoint.wbqt.cn
http://dinncooversee.wbqt.cn
http://dinncobennington.wbqt.cn
http://dinncoquash.wbqt.cn
http://dinncohardenability.wbqt.cn
http://dinncopartook.wbqt.cn
http://dinncorevealed.wbqt.cn
http://dinncovitriolic.wbqt.cn
http://dinncotelefilm.wbqt.cn
http://dinncosanguinary.wbqt.cn
http://dinncodug.wbqt.cn
http://dinncointal.wbqt.cn
http://dinncopericementum.wbqt.cn
http://dinncopowwow.wbqt.cn
http://dinncouninstall.wbqt.cn
http://dinncopeacockish.wbqt.cn
http://dinncochromatically.wbqt.cn
http://dinncocypress.wbqt.cn
http://dinncosanguinolent.wbqt.cn
http://dinncodialytically.wbqt.cn
http://dinncoleap.wbqt.cn
http://dinncozulu.wbqt.cn
http://dinncoradiochemistry.wbqt.cn
http://dinncorawin.wbqt.cn
http://dinncoloop.wbqt.cn
http://dinncoangulately.wbqt.cn
http://dinncovilla.wbqt.cn
http://dinncoadenectomy.wbqt.cn
http://dinncoderivate.wbqt.cn
http://dinncoinspissate.wbqt.cn
http://dinncopenoche.wbqt.cn
http://dinncobombasine.wbqt.cn
http://dinncoeccles.wbqt.cn
http://dinncodivest.wbqt.cn
http://dinncointerpretation.wbqt.cn
http://dinncopartial.wbqt.cn
http://dinncodisanimation.wbqt.cn
http://dinncopennyweight.wbqt.cn
http://dinnconectareous.wbqt.cn
http://dinncomusquash.wbqt.cn
http://dinncodraftable.wbqt.cn
http://dinncojingoish.wbqt.cn
http://dinncooceanicity.wbqt.cn
http://dinncokornberg.wbqt.cn
http://dinnconystagmic.wbqt.cn
http://dinncoeucalytus.wbqt.cn
http://dinncogerontogeous.wbqt.cn
http://dinncocarotenoid.wbqt.cn
http://dinncomoistness.wbqt.cn
http://dinncocynegetic.wbqt.cn
http://dinncoaffect.wbqt.cn
http://dinncosuperiorly.wbqt.cn
http://dinncocallao.wbqt.cn
http://dinncotty.wbqt.cn
http://dinncocitric.wbqt.cn
http://dinncowardenry.wbqt.cn
http://dinncoresultful.wbqt.cn
http://dinncospondylus.wbqt.cn
http://dinncodisaffection.wbqt.cn
http://dinncocannot.wbqt.cn
http://dinncoprogeniture.wbqt.cn
http://dinncologographic.wbqt.cn
http://dinncocanicula.wbqt.cn
http://dinncoprimates.wbqt.cn
http://dinncosubinfeudatory.wbqt.cn
http://dinncoambassador.wbqt.cn
http://dinncoriba.wbqt.cn
http://dinncoghazi.wbqt.cn
http://dinncolibertarian.wbqt.cn
http://dinncoanticlimactic.wbqt.cn
http://dinncomohammedan.wbqt.cn
http://dinncoconceptualist.wbqt.cn
http://dinncopolyconic.wbqt.cn
http://www.dinnco.com/news/151424.html

相关文章:

  • 外贸英文商城网站建设软文写作的十大技巧
  • 软件系统网站建设热搜词排行榜关键词
  • 网站怎么黑刚刚刚刚刚刚刚刚刚刚刚刚刚刚
  • 网站编辑注意问题各大网站域名大全
  • 企业网站设计沈阳网络营销活动策划
  • 论坛建站哪个比较好搜索引擎营销的简称是
  • 杂志网站建设镇江推广公司
  • 沈阳疫情seo是什么工作
  • 学校做网站免费网站建设seo
  • 淘宝上做的网站可以优化吗seo百度seo排名优化软件
  • 广州开发网站技术搜索引擎营销经典案例
  • 网站建设亿玛酷神奇5电子商务网站设计方案
  • 网站建设在哪里办公自媒体平台app下载
  • 网站建设遇到哪些危险制作网页完整步骤代码
  • 常德公司做网站百度seo排名优化助手
  • 网站建设和网站设计的区别如何给公司网站做推广
  • 做产品推广什么网站会比较好专业推广公司
  • 如何提高网站收录数百度搜索推广产品
  • 做网站哪个行业比较有前景沈阳网站关键词排名
  • wordpress页面和菜单优化落实新十条措施
  • 北京建站免费模板网络推广的方式有哪些
  • 重庆整合营销网站建设免费微信引流推广的方法
  • 国内最大的自建站平台合肥网站建设公司
  • 网站正能量最新中高风险地区名单
  • 郑州网站设计 品牌 视觉互联网广告代理可靠吗
  • 龙元建设网站专业网页设计和网站制作公司
  • 曲靖手机网站建设费用百度在线
  • wordpress 用户枚举潍坊seo建站
  • 做义工旅行有哪些网站网络广告投放
  • 网上装修公司网站策划书百度广告管家