1 回答
TA貢獻1911條經驗 獲得超7個贊
您可以通過這種方式找到模板中的所有關鍵字。
regexp.MustCompile(`{{-? ?(template|partial) \"([^() ]*)\" ?.* ?-?}}`)當您遇到更復雜的情況時,哪里partial只是您使用的示例。您可以刪除它或自行添加更多關鍵字。
其他部分,比如CollectFiles我認為不是那么重要,如果有人需要參考下面
然后只需要過濾模板,找出當前文件使用的模板。
最后,無論何時添加模板,代碼都不會更新。(除非您想更新站點上下文)
我在Github上寫了一個可以運行的簡單例子,這樣人們就可以知道我想做什么。
子模板的嵌套。
如果你想處理這個。嘗試使用這個功能
現在這將起作用
如果渲染: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 關注
- 105 瀏覽
添加回答
舉報
