Page
這是一個方便的方法,特別適用於從短代碼和頁面模板中調用的部分模板。
layouts/shortcodes/foo.html
{{ partial "my-partial.html" . }}
當短代碼調用部分時,它會傳遞當前的上下文(即點)。該上下文包括 Page
、Params
、Inner
和 Name
等標識符。
layouts/_default/single.html
{{ partial "my-partial.html" . }}
當頁面模板調用部分時,它也會傳遞當前上下文(即點)。但在這種情況下,點 就是 Page
物件。
layouts/partials/my-partial.html
The page title is: {{ .Page.Title }}
為了處理這兩種情況,部分模板必須能夠使用 Page.Page
訪問 Page
物件。