Dynamic Routing - Create new index page and access all Posts


#1

If you’re looking for some help, it’s important to provide as much context as possible so that people are able to assist you. Try to always mention:

  • What’s your URL? This is the easiest way for others to debug your issue
    http://vfpoetry.com/

  • What version of Ghost are you using?
    1.24.9

  • What configuration?

The default configuration

  • What browser?
  • What errors or information do you see in the console?
  • What steps could someone else take to reproduce the issue you’re having?

I have this website https://vfpoetry.com/ and I would like to create an index page on the
https://vfpoetry.com/my-poems/ path and I would like to access the whole list of posts.

What I have done is used the following dynamic routing

routes:

collections:
  /:
    permalink: '{globals.permalinks}' # special 1.0 compatibility setting. See the docs for details.
    template:
      - index
  /my-poems/:
    permalink: /my-poems/
    template:
      - index

taxonomies:
  tag: /tag/{slug}/
  author: /author/{slug}/

and I’ve created a template named my-poems.hbs with the following html

{{!< default}}
{{! The tag above means - insert everything in this file into the {body} of the default.hbs template }}

{{! The main content area on the homepage }}
<main id="content" class="content mxn2 js-grid">

    {{#foreach posts}}
        <article class="{{post_class}} px2 border-box post--grid {{#if featured}}post--featured{{/if}}">
            <div class="p3 bg-white box-shadow">
                {{#if feature_image}}
                    <div class="post-image mxn3 mb3">
                        <a href="{{url}}"><img src="{{img_url feature_image}}" alt=""></a>
                    </div>
                {{/if}}
                <header class="post-header">
                    <h2 class="post-title mt0 break-word"><a class="black" href="{{url}}">{{{title}}}</a></h2>
                </header>
                <div class="post-excerpt h5 light">
                    <p class="mb0">{{excerpt}} <a class="read-more" href="{{url}}">&raquo;</a></p>
                </div>
            </div>
        </article>
    {{/foreach}}


</main>

{{! Previous/next page links - displayed on every page }}
{{pagination}}

Now When I visit the page I cannot see the posts data, its empty.

How can I access the posts from that page? I just need the whole post list and not a filtered one.


#2

Have you read https://docs.ghost.org/docs/dynamic-routing already?


#3

Yes and apparently I should have access to the #posts context but in reality its not. How can I debug this?


#4

You have to use a filter, otherwise the first collection will own every post.


#5

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.