1 回答

TA貢獻(xiàn)1911條經(jīng)驗(yàn) 獲得超7個(gè)贊
您可以通過(guò)這種方式找到模板中的所有關(guān)鍵字。
regexp.MustCompile(`{{-? ?(template|partial) \"([^() ]*)\" ?.* ?-?}}`)
當(dāng)您遇到更復(fù)雜的情況時(shí),哪里partial
只是您使用的示例。您可以刪除它或自行添加更多關(guān)鍵字。
其他部分,比如CollectFiles
我認(rèn)為不是那么重要,如果有人需要參考下面
然后只需要過(guò)濾模板,找出當(dāng)前文件使用的模板。
最后,無(wú)論何時(shí)添加模板,代碼都不會(huì)更新。(除非您想更新站點(diǎn)上下文)
我在Github上寫(xiě)了一個(gè)可以運(yùn)行的簡(jiǎn)單例子,這樣人們就可以知道我想做什么。
子模板的嵌套。
如果你想處理這個(gè)。嘗試使用這個(gè)功能
現(xiàn)在這將起作用
如果渲染:index.gohtml
不僅base.gohtml
包含而且還包含 { head.gohtml
, navbar.gohtml
, footer.gohtml
}
<!-- index.gohtml -->
{{- template "base.gohtml" . -}} <!-- ?? -->
{{define "head"}}
<style>h2 {background-color: yellow;}
</style>
{{end}}
{{define "body"}}
<h2>Welcome to XXX</h2>
{{end}}
在哪里base.gohtml
{{template "head.gohtml" . -}}
{{template "navbar.gohtml"}}
{{- block "body" . -}}
{{- end -}}
{{template "footer.gohtml"}}
- 1 回答
- 0 關(guān)注
- 76 瀏覽
添加回答
舉報(bào)