<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                模板語法 go 統一使用了 {{ 和 }} 作為左右標簽,沒有其他的標簽符號。 使用 . 來訪問當前位置的上下文 使用 $ 來引用當前模板根級的上下文 使用 $var 來訪問創建的變量 模板中支持的 go 語言符號 ~~~ {{"string"}} // 一般 string {{`raw string`}} // 原始 string {{'c'}} // byte {{print nil}} // nil 也被支持 ~~~ 基本語法代碼: ~~~ |-- admin | |--controllers | `-- user.go ~~~ ~~~ package admin import ( "github.com/astaxie/beego" ) type UserController struct { beego.Controller } func (this *UserController) Index() { // if … else … end this.Data["if"] = true this.Data["else"] = "else" this.Data["elseif"] = false /* range … end 支持的類型為 array, slice, map, channel range 循環內部的 . 改變為以上類型的子元素 對應的值長度為 0 時,range 不會執行,. 不會改變 */ pages := []struct { Num int }{{10}, {20}, {30}} this.Data["Total"] = 100 this.Data["Pages"] = pages // with … end type stu struct { Name string Age int } this.Data["struct"] = &stu{Name: "Murphy", Age: 28} // define 可以用來定義自模板,可用于模塊定義和模板嵌套 this.Data["define"] = "this is define" this.TplName = "admin/user/index.html" } ~~~ ~~~ |-- views | |--admin | |--user | `-- index.html ~~~ ~~~ <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> </head> <body> this is view admin/user/index.html <br/> 語法 if … else … end :<br/> {{if .if}} this if = true<br/> {{end}} 嵌套的循環 :<br/> {{if .if}} this if = true<br/> {{if .else}} this else = "else" {{end}} {{end}}<br/> else if 使用 : {{if .elseif}} this elseif = false {{else if .if}} this if = true<br/> {{else}} else is ??? {{end}}<br/> 語法 range … end :<br/> 使用 .Num 輸出子元素的 Num 屬性,使用 $. 引用模板中的根級上下文 :<br/> {{range .Pages}} {{.Num}} of {{$.Total}}<br/> {{end}} 使用創建的變量,在這里和 go 中的 range 用法是相同的 :<br/> {{range $index, $elem := .Pages}} {{$index}} - {{$elem.Num}} - {{.Num}} of {{$.Total}}<br/> {{end}} range else :<br/> {{range .Page}} {{.Num}}... {{else}} 當 .Pages 為空 或者 長度為 0 時會執行這里 {{end}}<br/> 語法 with … end :<br/> with 用于重定向 :<br/> {{with .struct}} ---{{.Name}} {{end}}<br/> with 對變量賦值操作 : <br/> {{with $value := "My name is %s"}} {{printf . "Murphy"}} {{end}}<br/> with else : {{with .struct1}} this is with else true {{else}} this is with else false {{/* 當 pipeline 為空時會執行這里 */}} {{end}}<br/> 語法 define 用來定義自模板,可用于模塊定義和模板嵌套 :<br/> {{define "loop"}} define:<li>{{.define}}</li> {{end}} 語法 template 調用模板 :<br/> <ul> template:{{template "loop" .}} </ul> <!-- 模板注釋:允許多行文本注釋,不允許嵌套 --> {{/* comment content support new line */}} </body> </html> ~~~ 瀏覽器訪問: http://127.0.0.1:8080/admin/user/index 瀏覽器返回: ~~~ this is view admin/user/index.html 語法 if … else … end : this if = true 嵌套的循環 : this if = true this else = "else" else if 使用 : this if = true 語法 range … end : 使用 .Num 輸出子元素的 Num 屬性,使用 $. 引用模板中的根級上下文 : 10 of 100 20 of 100 30 of 100 使用創建的變量,在這里和 go 中的 range 用法是相同的 : 0 - 10 - 10 of 100 1 - 20 - 20 of 100 2 - 30 - 30 of 100 range else : 當 .Pages 為空 或者 長度為 0 時會執行這里 語法 with … end : with 用于重定向 : ---Murphy with 對變量賦值操作 : My name is Murphy with else : this is with else false 語法 define 用來定義自模板,可用于模塊定義和模板嵌套 : 語法 template 調用模板 : template: define: this is define ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看