Iterating over pages in themes

{{#foreach helper can’t iterate over pages.
As pages are posts, is there a way to iterate over posts and filter those which are pages?

Posts and Pages are stored in the same database table, but that’s the only similarity they have; the way Posts and Pages are handled by Ghost are independent of each other.

I’m not sure what you mean by pages are not iterable using the foreach helper - this works:

{{#get "pages" limit=5 as |pages|}}
    {{#foreach pages as |page|}}
        {{page.title}}
    {{/foreach}}
{{/get}}

Can you share what you’re trying to do?

1 Like

Exaclty what I was looking for.

In fact I noticed that posts is globally available but not always full filled, on the other hand I always need the #get helper to have access to pages.

I needed it to set my navigation by page instead of the default one, I got it with the following code:

{{#if @site.navigation}}
<ul class="nav">
    <!-- Loop through the pages -->
    {{#get "pages" order="published_at desc" as |pages|}}
    {{#foreach pages as |page|}}
    <li class="page-{{page.slug}}{{#if current}} page-current{{/if}}">
        <a href="{{page.url}}">{{page.title}}</a>
    </li>
    {{/foreach}}
    {{/get}}
    <!-- End the loop -->
</ul>
{{/if}}