Get helper to fetch featured posts, else block not executing
See original GitHub issueI’m using the get helper to output a featured posts carousel. If there are no featured posts, blog cover image should be displayed instead. It was working fine with Ghost 0.11.x version, but with Ghost 1.0 the else block is not executing even though there are no posts marked as featured.
Here is my code:
{{#get "posts" filter="featured:true" limit="5" include="author,tags" as |featured|}}
<div id="featured-slider" class="featured-slider">
{{#foreach featured}}
<div>
{{#if feature_image}}
<div class="slide-bg" style="background-image: url({{feature_image}})"></div>
{{/if}}
<div class="slide-content">
{{#if tags}}
<div class="post-tags">
{{tags separator=""}}
</div>
{{/if}}
<h2 class="post-title"><a href="{{{url}}}">{{title}}</a></h2>
</div>
</div>
{{/foreach}}
</div><!-- .featured-slider -->
{{else}}
<div class="cover">
{{#if @blog.cover_image}}
<div class="cover-bg" style="background-image: url({{@blog.cover_image}})"></div>
{{/if}}
<div class="cover-content">
<h2 class="hero-title">{{@blog.title}}</h2>
<p class="hero-text">{{@blog.description}}</p>
</div><!-- .cover-content -->
</div><!-- .cover -->
{{/get}}
Technical details:
- Ghost Version: 1.0
- Node Version: 6.11.1
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Ghost Handlebars Theme Helpers: get
Make custom queries to the Ghost API using the get helper and fetch publicly available data. Read more about Ghost themes!
Read more >Trying to retrieve a document by _id directly in template helper not ...
unfortunately I can not use iron router. So I need to get the id manually and grab it through the url. Is there...
Read more >Helpers - Zendesk Developer Docs
Use the isnt helper to execute a template block conditionally, given an expression result. If the comparison evaluates to true (the two values...
Read more >Handlebars Helpers Reference | BigCommerce Dev Center
Differs from the get helper in that this helper will return the actual object including the given property key. This helper does not...
Read more >Top 10 Most Common Node.js Developer Mistakes - Toptal
// Trying to fetch an user object from the database. Node.js is free to run other parts of the code from the moment...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@astab in this case you should be able to use an explicit
{{#if}}
conditional:Hi @astab, this behaviour deliberately changed between 0.11.x and 1.0.
The way this worked in 0.11.0 was confusing, because the
{{else}}
needed to belong to get instead of foreach, and yet it was the foreach helper that most people are used to and which had the else block documented. Following a discussion it was decided to change this.Unfortunately, this has been missed in our changelog for 1.0.0 and other documentation. I’m in the process of updating that now and have added a new section to the docs.
Hopefully this gets you on your way!
Closing this as we’re tracking outstanding documentation tasks to wrap up 1.0.0