第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在 Go Gin 中使用模板獲取動態(tài)內(nèi)容

如何在 Go Gin 中使用模板獲取動態(tài)內(nèi)容

Go
蕭十郎 2022-01-17 18:13:14
我有一個簡單的 Go / Gin 網(wǎng)絡(luò)應(yīng)用程序。我需要在 html 模板中放入一些動態(tài)內(nèi)容。例如,我有幾張表(數(shù)字是動態(tài)的)和幾行(數(shù)字是動態(tài)的)。我需要將它們放在 html 模板中。有沒有辦法在代碼中組合模板?我更喜歡使用模板而不是在代碼中構(gòu)建表格。我已經(jīng)檢查了一個教程https://github.com/gin-gonic/gin但它沒有被覆蓋。
查看完整描述

1 回答

?
www說

TA貢獻(xiàn)1775條經(jīng)驗(yàn) 獲得超8個贊

您可以使用define定義部分和template混合多個 HTML 部分。


package main


import (

    "html/template"


    "github.com/gin-gonic/gin"

)


var (

    partial1 = `{{define "elm1"}}<div>element1</div>{{end}}`

    partial2 = `{{define "elm2"}}<div>element2</div>{{end}}`

    body     = `{{template "elm1"}}{{template "elm2"}}`

)


func main() {

    // Or use `ParseFiles` to parse tmpl files instead 

    t := template.Must(template.New("elements").Parse(body))


    app := gin.Default()

    app.GET("/", func(c *gin.Context) {

        c.HTML(200, "elements", nil)

    })

    app.Run(":8000")

}

這是閱讀https://gohugo.io/templates/go-templates/的好地方


查看完整回答
反對 回復(fù) 2022-01-17
  • 1 回答
  • 0 關(guān)注
  • 243 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號