GHOST CMS - index Index

Index

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

Use: {{# is "index"}} {{/ is}} This context is detected.

Description Description

index is the name for the main post list in your Ghost site, the index context includes the home page and subsequent pages of the main post list. The index context is always paired with either the home context when on the first page of your site, or the pagecontext when on subsequent pages.

The main index is the name of the post list Ghost in your site, index context includes a list of the main post of the home page and subsequent pages. When pagecontext on the first page or subsequent pages of your site, indexing and context always home match the context.

Routes Route

The index context is present on both the root URL of the site, e.g. / and also on subsequent pages of the post list, which live at /page/:num/. All routes are customisable with dynamic routing.

index in the context of the root URL of the site, such as /, also post on the following pages list in  /page/:num/. All routes are customizable dynamic routing.

Templates Templates

The index context is rendered with index.hbs by default. This template is required in all Ghost themes. If there is a home.hbs present in the theme, the home page will be rendered using that instead.

Note that the index.hbs template is also used to output the tag and author contexts, if no specific tag.hbs or author.hbs templates are provided.

Index is the context  index.hbs渲染of the default. This template at all Ghost topics are required. If there is  home.hbspresented in the subject, we will use it to render the home page.

Note index.hbs can also use a template to output tag and author context. If no tag.hbs or  author.hbstemplate.

Data Data

The index context provides templates with access to an array of post objects and a pagination object. As with all contexts, all of the @blog global data is also available.

The number of posts provided will depend on the post per page setting which you can configure in your package.json file. The array will provide the correct posts for the current page number, with the posts ordered chronologically, newest first. Therefore on the home page, the theme will have access to the first 6 posts by default. On /page/2/ the theme will have access to posts 7-12.

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.

index Context provides access to post an array of objects and templates page objects. Like all contexts, all @blog global data is available.

The number of articles provided will depend on each page article that you can configure in the package, set in package.json  file. Array will provide the correct current page postings, postings in chronological order, the first date. Therefore, on the home page, the default theme before accessing six articles. In / page / 2 /, the theme will be displayed Write 7-12 articles.

You may be used {{#foreach 'posts'}} {{/ foreach}} cycles each post. Template code block will render each post, post and access to all object properties.

Paging object provides anywhere are the same. The best way is to use the output paging paging assistant.

Helpers assistant

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

If your theme does have a tag.hbs and author.hbs file all outputting similar post lists 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.

Using {{#foreach 'posts'}} {{/ foreach}} is the best way to traverse the posts and each post output.

If your subject has tag.hbs and author.hbs list of all the articles similar output file, you may want to use a partial list of articles to define your terms, such as {{> "loop"}} . Here is a detailed example illustrates this point.

{{pagination}} is the best method of outputting helper tab. It is completely customizable.

Example Code Case Code

index.hbs
<header>
  <h1 class="page-title">{{@blog.title}}</h1> <h2 class="page-description">{{@blog.description}}</h2> </header> <main role="main"> <!-- This is the post loop - each post will be output using this markup --> {{#foreach posts}} <article class="{{post_class}}"> <header class="post-header"> <h2><a href="{{url}}">{{title}}</a></h2> </header> <section class="post-excerpt"> <p>{{excerpt words="26"}} <a class="read-more" href="{{url}}">...</a></p> </section> <footer class="post-meta"> {{#if primary_author.profile_image}}<img src="{{primary_author.profile_image}}" alt="Author image" />{{/if}} {{primary_author}} {{tags prefix=" on "}} <time class="post-date" datetime="{{date format='YYYY-MM-DD'}}">{{date format="DD MMMM YYYY"}}</time> </footer> </article> {{/foreach}} </main> <!-- Previous/next page links - displayed on every page --> {{pagination}} 

Home

home is a special context which refers to page 1 of the index. If home is set, index is always set as well. home can be used to detect that this is specifically the first page of the site and not one of the subsequent pages.

home is a special context, refers to the index of the first page. If the home setting, the index is always set. home can be used to detect this is the first page of the website, rather than one of the pages that follow.

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

Routes

The route for the home page is always /.

Templates

The default template for the home page is index.hbs. You can optionally add a home.hbs template to your theme which will be used instead.

Data

The data available on the home page is exactly the same as described in the index context. The home page's posts will always be the first X posts ordered by published date with the newest first, where X is defined by the posts_per_page setting in the package.json file.

Guess you like

Origin www.cnblogs.com/QDuck/p/12080433.html