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

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

tmpl.Execute 和子文件 golang

tmpl.Execute 和子文件 golang

Go
喵喵時光機 2021-09-20 10:49:32
我需要幫助。我需要在子文件(,我的文本中的示例)中使用"html/template"的標(biāo)記({{.Title}},示例"article.html"):// ...type Page struct {    Test string}type News struct {    Page    Title string}func main() {    t, _ := template.ParseFiles(filepath+"core.tmpl", filepath+"article.tmpl")    p := &News{        Title: "TITLE",        Page: Page{            Test: "TITLE",        },    }    t.Execute(wr, p)}代碼core.tmpl:{{template "article"}}代碼article.tmpl:{{define "article"}}{{.Title}}<br><br>{{.Page.Test}}{{end}}
查看完整描述

1 回答

?
慕勒3428872

TA貢獻1848條經(jīng)驗 獲得超6個贊

在core.tmpl你必須使用


{{template "article" .}}

如果.最后沒有指定,模板將與nil數(shù)據(jù)一起執(zhí)行。指定.將傳遞.給調(diào)用模板的值。


引用text/template包文檔,Actions部分:


{{template "name"}}

    The template with the specified name is executed with nil data.


{{template "name" pipeline}}

    The template with the specified name is executed with dot set

    to the value of the pipeline.


查看完整回答
反對 回復(fù) 2021-09-20
  • 1 回答
  • 0 關(guān)注
  • 299 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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