惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

宝玉的分享
宝玉的分享
NISL@THU
NISL@THU
E
Exploit-DB.com RSS Feed
L
LINUX DO - 热门话题
L
Lohrmann on Cybersecurity
K
Kaspersky official blog
Project Zero
Project Zero
Cisco Talos Blog
Cisco Talos Blog
T
The Exploit Database - CXSecurity.com
P
Palo Alto Networks Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
T
Threatpost
S
Schneier on Security
G
GRAHAM CLULEY
The Hacker News
The Hacker News
T
Threat Research - Cisco Blogs
Scott Helme
Scott Helme
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
P
Privacy & Cybersecurity Law Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
Cyberwarzone
Cyberwarzone
C
CERT Recently Published Vulnerability Notes
T
Tor Project blog
AWS News Blog
AWS News Blog
Simon Willison's Weblog
Simon Willison's Weblog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
爱范儿
爱范儿
P
Privacy International News Feed
云风的 BLOG
云风的 BLOG
P
Proofpoint News Feed
S
Securelist
G
Google Developers Blog
The Last Watchdog
The Last Watchdog
Google Online Security Blog
Google Online Security Blog
美团技术团队
F
Fortinet All Blogs
小众软件
小众软件
Recorded Future
Recorded Future
V
Visual Studio Blog
B
Blog RSS Feed
H
Help Net Security
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Google DeepMind News
Google DeepMind News
Blog — PlanetScale
Blog — PlanetScale
博客园 - 聂微东
Stack Overflow Blog
Stack Overflow Blog
Martin Fowler
Martin Fowler
Latest news
Latest news
Spread Privacy
Spread Privacy
H
Heimdal Security Blog

博客园 - QDuck

Handlebars.js入门教程 GHOST CMS - Handlebars Themes - Further Reading GHOST CMS - Properties GHOST CMS - Redirects GHOST CMS - Channels GHOST CMS - Content Collections GHOST CMS - Content Taxonomies GHOST CMS - Custom Routes GHOST CMS - Google AMP谷歌地图 GHOST CMS - URLs & Dynamic Routing GHOST CMS - Responsive Images 图片显示 GHOST CMS - Editor编辑器 GHOST CMS - Utility Helpers公用事业帮手 GHOST CMS - Data Helpers GHOST CMS - Functional Helpers功能助手 GHOST CMS - Author作者 GHOST CMS - Page 页面 GHOST CMS - Post 文章 GHOST CMS - 索引Index
GHOST CMS - 标签Tag
QDuck · 2019-12-22 · via 博客园 - QDuck

Tag

Use: {{#is "tag"}}{{/is}} to detect this context

Description

Tags in Ghost each get their own page which lists out the associated posts. You are in the tag context when viewing the page thats lists all posts with that tag, as well as subsequent pages of posts. The tag context is not set on posts or pages with tags, only on the list of posts for that tag.

Routes

The default URL for tag pages is /tag/:slug/. The tag context is also set on subsequent pages of the post list, which live at /tag/:slug/page/:num/. The slug part of the URL is based on the name of the tag and can be configured in the tag admin, no other part of the URL can be configured at present.

Templates

The default template for a tag page is index.hbs.

You can optionally include a tag.hbs file in your theme which will be used for tag pages instead.

Additionally, you can provide a custom template for a specific tag. If there is a tag-:slug.hbs file with the :slug matching the tag's slug this will be used instead.

For example, if you have a tag 'photo' with the url /tag/photo/, adding a template called tag-photo.hbs will cause that template to be used for the photo tag instead of tag.hbs, or index.hbs.

These templates exist in a hierarchy. Ghost looks for a template which matches the slug (tag-:slug.hbs) first, then looks for tag.hbs and finally uses index.hbs if neither is available.

Data

When in the tag context, a template gets access to 3 objects: the tag object which matches the route, an array of post objects and a pagination object. As with all contexts, all of the @blog global data is also available.

Tag object

When outputting the tag attributes, you can use a block expression ({{#tag}}{{/tag}}) to drop into the tag scope and access all of the attributes.

Tag object attributes

  • id - the incremental ID of the tag
  • name - the name of the tag
  • description - a description of the tag
  • feature_image - the cover image associated with the tag
  • meta_title - custom meta title for the page
  • meta_description - custom meta description for the page
  • url - the web address for the tag's page

Post list

Each of the posts can be looped through using {{#foreach 'posts'}}{{/foreach}}. The template code inside the block will be rendered for each post, and have access to all of the post object attributes.

The pagination object provided is the same everywhere. The best way to output pagination is to use the pagination helper.

Helpers

The {{#tag}}{{/tag}} block expression is useful for accessing all of the author attributes. Once inside the tag you can access the attributes and use helpers like {{img_url}} and {{url}} to output the tag's details.

Using {{#foreach 'posts'}}{{/foreach}} is the best way to loop through the list of posts and output each one.

If your theme does have a tag.hbs and author.hbs file all outputting similar post lists to index.hbs you may wish to use a partial to define your post list item, e.g. {{> "loop"}}. There's an example showing this in detail below.

The {{pagination}} helper is the best way to output pagination. This is fully customisable, see the pagination helper docs for details.

Example Code

tag.hbs

<!-- Everything inside of #tag pulls data from the tag -->
{{#tag}}
  <header>
  	{{#if feature_image}}
    	<img src="{{feature_image}}" alt="{{name}}" />
    {{/if}}
  </header>

  <section class="author-profile">
  	<h1>{{name}}</h1>
    {{#if description}}
      <h2>{{description}}</h2>
    {{/if}}
  </section>
{{/tag}}

<main role="main">