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}}将传递给它一个上下文,并且仅当它在该上下文中时才执行所包含的块。

GHOST CMS -上下文概述 Context Overview的更多相关文章

  1. ZeroMQ接口函数之 :zmq_term - 终结ZMQ环境上下文(context)

    ZeroMQ 官方地址 :http://api.zeromq.org/4-0:zmq_term zmq_term(3) ØMQ Manual - ØMQ/4.1.0 Name zmq_term - 终 ...

  2. Tomcat部署web项目,虚拟目录,上下文(Context),WEB-INF,web.xml,servlet,404

    Web项目的uri模型大致如下: http://localhost:8080 (/context) (/resource) 站点/上下文/资源 一. Tomcat中指定上下文(Context) 方法一 ...

  3. javascript作用域(Scope),简述上下文(context)和作用域的定义

    网页制作Webjx文章简介:这篇文章将正面解决这个问题:简述上下文(context)和作用域的定义,分析可以让我们掌控上下文的两种方法,最后深入一种高效的方案,它能有效解决我所碰到的90%的问题. 作 ...

  4. 层叠上下文 Stacking Context

    层叠上下文 Stacking Context 在CSS2.1规范中,每个盒模型的位置是三维的,分别是平面画布上的x轴,y轴以及表示层叠的z轴.对于每个html元素,都可以通过设置z-index属性来设 ...

  5. (转)Docker镜像构建上下文(Context)

    镜像构建上下文(Context) Docker在构建镜像时,如果注意,会看到 docker build 命令最后有一个 ... 表示当前目录,而 Dockerfile 就在当前目录,因此不少初学者以为 ...

  6. Docker镜像构建上下文(Context)

    镜像构建上下文(Context) Dicker在构建镜像时,如果注意,会看到 docker build 命令最后有一个 ... 表示当前目录,而 Dockerfile 就在当前目录,因此不少初学者以为 ...

  7. Flask 上下文(Context)原理解析

    :first-child { margin-top: 0; } blockquote > :last-child { margin-bottom: 0; } img { border: 0; m ...

  8. 上下文(Context)和作用域(Scope)

    函数的每次调用都有与之紧密相关的作用域和上下文.从根本上来说,作用域是基于函数的,而上下文是基于对象的. 换句话说,作用域涉及到所被调用函数中的变量访问,并且不同的调用场景是不一样的.上下文始终是th ...

  9. OpenJDK源码研究笔记(十三):Javac编译过程中的上下文容器(Context)、单例(Singleton)和延迟创建(LazyCreation)3种模式

    在阅读Javac源码的过程中,发现一个上下文对象Context. 这个对象用来确保一次编译过程中的用到的类都只有一个实例,即实现我们经常提到的"单例模式". 今天,特意对这个上下文 ...

随机推荐

  1. windows下搭建dubbo 环境(dubbo-admin和服务提供者消费者)

    ---恢复内容开始--- 一.  dubbo-admin管理控制台 从 https://github.com/apache/dubbo-admin clone项目到本地. 修改dubbo-admin- ...

  2. 学会这8个优秀 Python 库用于业余项目,将大大减少程序员耗费的精力

    在数据库中即时保存数据:Dataset 当我们想要在不知道最终数据库表长什么样的情况下,快速收集数据并保存到数据库中的时候,Dataset 库将是我们的最佳选择.Dataset 库有一个简单但功能强大 ...

  3. 2019-9-11:渗透测试,基础学习,VMware安装centos 7

    VMware Workstation 15 Pro 安装Centos 7,详细图文步骤 1,点击VMware菜单栏的“文件”-->“新建虚拟机”,选择“典型”使用向导创建虚拟机,点击“下一步” ...

  4. springboot+logback日志输出企业实践(下)

    目录 1.引言 2. 输出 logback 状态数据 3. logback 异步输出日志 3.1 异步输出配置 3.2 异步输出原理 4. springboot 多环境下 logback 配置 5. ...

  5. setBounds方法,与setLayout(null)

    首先把相关容器的布局方式设为 setLayout(null); 然后调用组件的  setBounds() 方法 设置button的位置为(100,100) 长宽分别为 60,25 jButton.se ...

  6. SpringBoot第一次案例

    一.Spring Boot 入门 1.Spring Boot 简介 简化Spring应用开发的一个框架: 整个Spring技术栈的一个大整合: J2EE开发的一站式解决方案: 2.微服务 2014,m ...

  7. 感觉async await 异步编程 并不能提升性能?

    我有2个方法 代码相同 都是执行上传文件IO操作 一个同步 一个异步 接着我用POSTMAN 分别用200个线程 去同时测试2个接口 结果很意外 2个接口 同时执行完成的速度 异步更慢 之前经常看别人 ...

  8. 【Android - 自定义View】之自定义颜色渐变的Tab导航栏

    首先来介绍一下这个自定义View: (1)这个自定义View的名称叫做 GradientTab ,继承自View类: (2)这个自定义View实现了颜色渐变的Tab导航栏(仿微信主菜单),用户在左右滑 ...

  9. surfer白化

    surfer白化的方法: 方法一: 1.griddata需白化的文件(surfer处理成grd格式,也就是surfer绘图的基本数据格式) 注意:用surfer转换格式时,插值间距(spacing)大 ...

  10. 【合集】python 的一些妙用,推导式、三元表达式、with as 等

    自己常用的内置函数 函数如下: dir len str list tuple zip map reduce(现在并入了functools中) 常用的进制转换 Oct hex bin lambda 表达 ...