GHOST CMS -上下文概述 Context Overview


Context Overview上下文概述

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.


What is a context?什么是上下文

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.

It is the route that determines what data is meant to be shown and what template is used to render it.

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.

Rather than providing access to all data in all contexts, Ghost optimises what data is fetched using contexts to ensure publications are super fast.



使用 API 网关构建微服务-2


例如,在新发布的出版物POST上使用/welcome-to-ghost/ URL来显示文章的内容。使用了hbs模板,以及一些default.hbs的全局数据。这称为post上下文,在查看单个post时发生。


Using contexts使用上下文

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.


例如,{{meta_title}} helper根据当前上下文输出不同的内容。如果上下文是post,那么帮助器知道它可以使用 post.meta_title在标签上下文中,它使用tag.meta_title。


Goodbye 2019,Welcome 2020 | 沉淀 2020

© 版权声明
点赞0 分享