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.

Ghost主题中的每个页面都属于一个上下文,它决定使用哪个模板、哪些数据可用以及{{body_class}}助手输出什么内容。

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.

Ghost发布遵循的结构允许将url或路由映射到显示特定数据的视图。这些数据可以是一组文章、一篇文章或一个RSS提要。

它是决定要显示什么数据和使用什么模板来呈现数据的路由。

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

Ghost不是在所有上下文中提供对所有数据的访问,而是使用上下文来优化获取的数据,以确保发布的速度非常快。

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.

上下文在Ghost主题的构建块中扮演着重要的角色。除了确定可用的数据和要呈现的模板之外,上下文还与帮助程序交互,因为上下文还确定帮助程序输出的动态数据。

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

要检测主题中的上下文,请使用{{is}}助手。例如,在许多上下文之间共享的部分模板中,使用{{is}}将传递给它一个上下文,并且仅当它在该上下文中时才执行所包含的块。

最新文章

  1. web性能优化:详说浏览器缓存
  2. JavaScript学习笔记(一):介绍JavaScript的一些简单知识
  3. tcpproxy:基于 Swoole 实现的 TCP 数据包转发工具的方法
  4. C++ 排序函数 sort(),qsort()的含义与用法 ,字符串string 的逆序排序等
  5. poj 2975 Nim_最经典的Nim取石子
  6. python全栈开发-re模块(正则表达式)应用(字符串的处理)
  7. 视频下载四大神器—如何下载优酷/爱奇艺/腾讯/B站超清无水印视频
  8. ASP.NET Web API(MVC API)
  9. influxDB 0.9 C# 读写类
  10. 初级字典树查找在 Emoji、关键字检索上的运用 Part-2
  11. 20155206 2016-2017-2 《Java程序设计》第7周学习总结
  12. ubuntu VNC中Xfce4中Tab键失效的解决方法
  13. Bone Collector--hdu2602(01背包)
  14. Django 项目中设置缓存
  15. [原创]关于在VS解决方案下使用文件夹管理多个项目层次关系的说明
  16. 【codeforces】【比赛题解】#950 CF Round #469 (Div. 2)
  17. Java8新特性——StreamAPI(一)
  18. Python编辑器IDLE傻瓜入门
  19. select,poll,epoll用法
  20. 记.net 遇到的几个bug

热门文章

  1. 从壹开始 [ Ids4实战 ] 之六 ║ 统一角色管理(上)
  2. python+selenium +unittest生成HTML测试报告
  3. 仿微信 即时聊天工具 - SignalR (一)
  4. 【项目管理】Mybatis-Generator之最完美配置详解
  5. solr 的安装和配置
  6. IDEA IntelliJ/ DataGrip 修改自动补全快捷键
  7. Spring 之初识IOC和DI
  8. 联万物,+智能,为行业,华为云升级OceanConnect IoT全栈云服务
  9. 浏览器url访问tomcat出现错误 java.lang.NoSuchMethodError解决方法
  10. 一篇文章教你轻松使用fastjson