Each page in a Ghost theme belongs to a context, which determines which template is used, what data will be available and what content is output by the {{body_class}}
helper.api
Ghost主題中的每一個頁面都屬於一個上下文,它決定使用哪一個模板、哪些數據可用以及{{body_class}}助手輸出什麼內容。app
A Ghost publication follows a structure that allows URLs or routes to be mapped to views which display specific data. This data could be a list of posts, a single post or an RSS feed.ide
It is the route that determines what data is meant to be shown and what template is used to render it.post
For example, a post on a new publication with the/welcome-to-ghost/
URL is intended to show the content of the post, so the post.hbs
template is be used, as well as some global data from default.hbs
. This is called the post
context and occurs whenever you view a single post.fetch
Rather than providing access to all data in all contexts, Ghost optimises what data is fetched using contexts to ensure publications are super fast.flex
Ghost發佈遵循的結構容許將url或路由映射到顯示特定數據的視圖。這些數據能夠是一組文章、一篇文章或一個RSS提要。優化
它是決定要顯示什麼數據和使用什麼模板來呈現數據的路由。ui
例如,在新發布的出版物POST上使用/welcome-to-ghost/ URL來顯示文章的內容。使用了hbs模板,以及一些default.hbs的全局數據。這稱爲post上下文,在查看單個post時發生。url
Ghost不是在全部上下文中提供對全部數據的訪問,而是使用上下文來優化獲取的數據,以確保發佈的速度很是快。spa
Contexts play a big part in the building blocks of a Ghost theme. Besides determining what data is available and what template to render, contexts also interact with helpers, since the context also determines what dynamic data the helper outputs.
For example, the {{meta_title}}
helper outputs different things based on the current context. If the context is post
then the helper knows it can use post.meta_title
and in a tag
context it uses tag.meta_title
.
To detect a context in your theme, use the {{is}}
helper. For example, in a partial template that is shared between many contexts, using {{is}}
will pass it a context and only execute the contained block when it is in that context.
上下文在Ghost主題的構建塊中扮演着重要的角色。除了肯定可用的數據和要呈現的模板以外,上下文還與幫助程序交互,由於上下文還肯定幫助程序輸出的動態數據。
例如,{{meta_title}} helper根據當前上下文輸出不一樣的內容。若是上下文是post,那麼幫助器知道它能夠使用 post.meta_title
。在標籤上下文中,它使用tag.meta_title。
要檢測主題中的上下文,請使用{{is}}助手。例如,在許多上下文之間共享的部分模板中,使用{{is}}將傳遞給它一個上下文,而且僅當它在該上下文中時才執行所包含的塊。