I am trying to list related posts in a section. I have made it show featured posts that share some tag (excluding the actual post). This way:
{{#get “posts” filter=“featured:true+id:-{{post.id}}+tags:[{{post.tags}}]” limit=“3” as |featured|}}
{{#foreach featured}}
…
{{/foreach}}
{{/get}}
In case there are no posts matching all criteria I want it to show only posts matching tags, and in case there is none either I want to show featured posts. I implemented it that way:
{{#get “posts” filter=“featured:true+id:-{{post.id}}+tags:[{{post.tags}}]” limit=“3” as |featured|}}
{{#foreach featured}}
…
{{/foreach}}
{{else}}
{{#get “posts” filter=“id:-{{post.id}}+tags:[{{post.tags}}]” limit=“3” as |featured|}}
{{#foreach featured}}
…
{{/foreach}}
{{else}}
{{#get “posts” filter=“id:-{{post.id}}+featured:true” limit=“3” as |featured|}}
{{#foreach featured}}
…
{{/foreach}}
{{/get}}
{{/get}}
{{/get}}
The problem is that when there are no posts matching tags and featured instead of executing the else statement it shows an empty list. It works if I use tags:[{{primary_tag.slug}}] instead of tags:[{{post.tags}}]
Am I doing something wrong or is it a bug?
Also, is there a way such that if there are only two results matching tags and featured I show also a post (up to the limit of 3) which only matches being featured or the tags?