# Posts data inside Author context is empty

**URL:** <https://forum.ghost.org/t/posts-data-inside-author-context-is-empty/14540>\
**Category:** Routing\
**Created:** [May 20, 2020, 3:20pm UTC](https://forum.ghost.org/t/posts-data-inside-author-context-is-empty/14540 "2020-05-20T15:20:11Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![dan.2rational](https://avatars.discourse-cdn.com/v4/letter/d/ac8455/32.png) [@dan.2rational](https://forum.ghost.org/u/dan.2rational)\
**Post date:** [May 20, 2020, 3:20pm UTC](https://forum.ghost.org/t/posts-data-inside-author-context-is-empty/14540/1 "2020-05-20T15:20:11Z")

</div>

I’m running a locally installed version of Ghost 3.14, working on the author.hbs template. I’ve found that following the instructions here:

[https://ghost.org/docs/api/v3/handlebars-themes/context/author/](https://ghost.org/docs/api/v3/handlebars-themes/context/author/)

I get all of the author data just fine, but using a {{#foreach “posts”}} returns an array of five empty items. For example, in my template:

```
{{#author}}
...author information here...
<h2>Posts by {{name}}</h2>
{{#foreach "posts"}}
  <p>Title: {{title}}</p>
{{/foreach}}

```

Returns the following HTML:

```
<h2>Posts by author</h2>
<p>Title:</p>
<p>Title:</p>
<p>Title:</p>
<p>Title:</p>
<p>Title:</p>

```

I deleted all of the starter posts, and there are definitely more than 5 posts in my installation.

I do have a modified routes.yaml file - could that have something to do with the issue?

Thanks!

routes.yaml

```
routes:
  /signup/: members\signup
  /signin/: members\signin
  /account/: members\account
  /support/: members\support

collections:
  /:
    permalink: /{slug}/
    template: index
    filter: tags:-[comic,shop,newsletter]
  /comic/:
    permalink: /comic/{slug}/
    template: comic
    filter: primary_tag:comic
  /shop/:
    permalink: /shop/{slug}/
    template: shop
    filter: primary_tag:shop

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

```

---

<div class="post-metadata">

**Author:** ![DavidDarnes](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/daviddarnes/32/3533_2.png) [@DavidDarnes](https://forum.ghost.org/u/DavidDarnes)\
**Post date:** [May 20, 2020, 3:25pm UTC](https://forum.ghost.org/t/posts-data-inside-author-context-is-empty/14540/2 "2020-05-20T15:25:34Z")

</div>

Hey @dan.2rational 👋

Could you try writing out the `foreach` loop without the quotes? Like so:

```auto
{{#foreach posts}}
  <p>Title: {{title}}</p>
{{/foreach}}

```

This looks like a typo in our docs. We’ll get this amended asap!

---

<div class="post-metadata">

**Author:** ![dan.2rational](https://avatars.discourse-cdn.com/v4/letter/d/ac8455/32.png) [@dan.2rational](https://forum.ghost.org/u/dan.2rational)\
**Post date:** [May 20, 2020, 3:28pm UTC](https://forum.ghost.org/t/posts-data-inside-author-context-is-empty/14540/3 "2020-05-20T15:28:08Z")

</div>

@DavidDarnes Thanks for the quick reply!

That causes the loop to return nothing. All I get is the h2 element.

Thanks again!

---

<div class="post-metadata">

**Author:** ![DavidDarnes](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/daviddarnes/32/3533_2.png) [@DavidDarnes](https://forum.ghost.org/u/DavidDarnes)\
**Post date:** [May 20, 2020, 3:31pm UTC](https://forum.ghost.org/t/posts-data-inside-author-context-is-empty/14540/4 "2020-05-20T15:31:00Z")

</div>

Oh really? In your example the closing `{{/author}}` is missing, do you have that in your template?

---

<div class="post-metadata">

**Author:** ![dan.2rational](https://avatars.discourse-cdn.com/v4/letter/d/ac8455/32.png) [@dan.2rational](https://forum.ghost.org/u/dan.2rational)\
**Post date:** [May 20, 2020, 3:31pm UTC](https://forum.ghost.org/t/posts-data-inside-author-context-is-empty/14540/5 "2020-05-20T15:31:54Z")

</div>

I do - everything else in the template renders correctly.

That does beg a question - should the {{#foreach}} loop be INSIDE the {{#author}} tags?

---

<div class="post-metadata">

**Author:** ![DavidDarnes](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/daviddarnes/32/3533_2.png) [@DavidDarnes](https://forum.ghost.org/u/DavidDarnes)\
**Post date:** [May 20, 2020, 3:35pm UTC](https://forum.ghost.org/t/posts-data-inside-author-context-is-empty/14540/6 "2020-05-20T15:35:15Z")

</div>

Oops yep you’re right. In Casper it’s after the author context:

> <https://github.com/TryGhost/Casper/blob/main/author.hbs#L45-L57>

---

<div class="post-metadata">

**Author:** ![dan.2rational](https://avatars.discourse-cdn.com/v4/letter/d/ac8455/32.png) [@dan.2rational](https://forum.ghost.org/u/dan.2rational)\
**Post date:** [May 20, 2020, 3:44pm UTC](https://forum.ghost.org/t/posts-data-inside-author-context-is-empty/14540/7 "2020-05-20T15:44:27Z")

</div>

That got it! Thank you!

Just for clarification - is it the author.hbs template that somehow filters the posts by author? Because it _does_ filter by author!

Last question - if I want to filter the list of returned posts for the author, does the foreach helper accept a filter? I tested it:

`{{#foreach posts filter="tags:-shop"}}`

But that still returns posts that are products in our shop that have a primary tag of ‘shop’ (integration with Shopify that works REALLY nicely!).

Thanks again!

---

<div class="post-metadata">

**Author:** ![DavidDarnes](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/daviddarnes/32/3533_2.png) [@DavidDarnes](https://forum.ghost.org/u/DavidDarnes)\
**Post date:** [May 20, 2020, 4:22pm UTC](https://forum.ghost.org/t/posts-data-inside-author-context-is-empty/14540/8 "2020-05-20T16:22:50Z")

</div>

You’ll be better off using the `#get` helper within the context of the author so you can fine tune it a bit more. Here’s an example:

```auto
  {{#get "posts" filter="authors:{{slug}}+tags:-shop" limit="all"}}
      {{#foreach posts}}
          <li><a href="{{url}}">{{title}}</a></li>
      {{/foreach}}
  {{/get}}
{{/author}}

```

---

<div class="post-metadata">

**Author:** ![dan.2rational](https://avatars.discourse-cdn.com/v4/letter/d/ac8455/32.png) [@dan.2rational](https://forum.ghost.org/u/dan.2rational)\
**Post date:** [May 20, 2020, 4:48pm UTC](https://forum.ghost.org/t/posts-data-inside-author-context-is-empty/14540/9 "2020-05-20T16:48:34Z")

</div>

Excellent! Thank you so much!

---

<div class="post-metadata">

**Author:** ![dan.2rational](https://avatars.discourse-cdn.com/v4/letter/d/ac8455/32.png) [@dan.2rational](https://forum.ghost.org/u/dan.2rational)\
**Post date:** [May 20, 2020, 5:02pm UTC](https://forum.ghost.org/t/posts-data-inside-author-context-is-empty/14540/10 "2020-05-20T17:02:18Z")

</div>

Just for posterity sake, the solution is different depending on what one wants to do.

To lists posts by an author on author.hbs, use the marked solution (#foreach helper **outside** the #author context).

To filter the posts returned, it’s necessary to use the #get helper, **but this must be done inside the #author context** :

```
{{#author}}
  ...author information here...
  <h2>Posts by {{name}}</h2>
  {{#get "posts" filter="author:{{slug}}+tags:-[tags to filter here]" limit="all"}}
    {{#foreach "posts"}}
      <p>Title: {{title}}</p>
    {{/foreach}}
  {{/get}}
{{/author}}

```

This way, the {{slug}} works inside the filter. 🙂

---

<div class="post-metadata">

**Author:** ![DavidDarnes](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/daviddarnes/32/3533_2.png) [@DavidDarnes](https://forum.ghost.org/u/DavidDarnes)\
**Post date:** [May 21, 2020, 9:55am UTC](https://forum.ghost.org/t/posts-data-inside-author-context-is-empty/14540/11 "2020-05-21T09:55:14Z")

</div>

Appreciate the clarity and sharing your findings in full @dan.2rational 🙌
