























Use: {{#is "page"}}{{/is}} to detect this context
Whenever you're viewing a static page, you're in the page context. The page context is not set on posts, which uses the post context instead.
The URL used to render a static page is always /:slug/. This cannot be customised, unlike post permalinks.
The default template for a page is post.hbs.
You can optionally include a page.hbs file in your theme which will be used for pages instead.
Additionally, you can provide a custom template for a specific page. If there is a page-:slug.hbs file with the :slug matching the static page's slug this will be used instead.
For example, if you have an 'About' page with the url /about/, adding a template called page-about.hbs will cause that template to be used for the about page, instead of page.hbs, or post.hbs.
These templates exist in a hierarchy. Ghost looks for a template which matches the slug (page-:slug.hbs) first, then looks for page.hbs and finally uses post.hbs if neither is available.
The page context provides access to the post object which matches the route. A page is just a special type of post, so the data object is called a post, not a page. As with all contexts, all of the @blog global data is also available.
When outputting the page, you can use a block expression ({{#post}}{{/post}}) to drop into the post scope and access all of the attributes. All of the data available for a page is the same as the data for a post. See a full list of attributes below:
falsetrue if the post is a static page. Defaults to falseUsing the {{#post}}{{/post}} block expression is the key trick to having a happy time theming your static page. Once inside of the page, you can use any of these useful helpers (and many more) to output your page's data:
{{title}}, {{content}}, {{url}}, {{author}}, {{date}}, {{excerpt}}, {{img_url}}, {{post_class}}], {{tags}}.
page.hbs
<!-- Everything inside the #post tags pulls data from the static page -->
{{#post}}
<article class="{{post_class}}">
<header class="page-header">
<h1 class="page-title">{{title}}</h1>
<section class="page-meta">
<time class="page-date" datetime="{{date format='YYYY-MM-DD'}}">
{{date format="DD MMMM YYYY"}}
</time>
{{tags prefix=" on "}}
</section>
</header>
<section class="page-content">
{{content}}
</section>
</article>
{{/post}}
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。