Ghost handlebars.js {{#has tag =“Top”}}不起作用

时间:2016-04-09 07:23:12

标签: handlebars.js ghost

在我的loop.hbs模板中,我试图让Ghost将标记为“Top”的帖子固定到顶部。我正在使用{{#has}}帮助器和{{#foreach posts}}

见下面的代码。我得到的行为是只有{{^has tag="Top"}}(即第二个foreach循环)才有效。

关于我可能做错什么的任何线索?

{{#foreach posts}}
    {{#has tag="Top"}}
        <article class="{{post_class}} top-post" style="background-color:lightgray">
            <header class="post-header">
                <h2 class="post-title"><a href="{{url}}">{{{title}}}</a></h2>
            </header>
            <section class="post-excerpt">
                <p>{{excerpt words="26"}} <a class="read-more" href="{{url}}">&raquo;</a></p>
            </section>
            <footer class="post-meta">
                {{#if author.image}}<img class="author-thumb" src="{{author.image}}" alt="{{author.name}}" nopin="nopin" />{{/if}}
                {{author}}
                {{tags prefix=" on "}}
                <time class="post-date" datetime="{{date format='YYYY-MM-DD'}}">{{date format="DD MMMM YYYY"}}</time>
            </footer>
        </article>
    {{/has}}
{{/foreach}}

{{! All the code above doesn't seem to be working.  Only the below code outputs posts to the blog homepage }}
{{#foreach posts}}
     {{^has tag="Top"}}
        <article class="{{post_class}}">
            <header class="post-header">
                <h2 class="post-title"><a href="{{url}}">{{{title}}}</a></h2>
            </header>
            <section class="post-excerpt">
                <p>{{excerpt words="26"}} <a class="read-more" href="{{url}}">&raquo;</a></p>
            </section>
            <footer class="post-meta">
                {{#if author.image}}<img class="author-thumb" src="{{author.image}}" alt="{{author.name}}" nopin="nopin" />{{/if}}
                {{author}}
                {{tags prefix=" on "}}
                <time class="post-date" datetime="{{date format='YYYY-MM-DD'}}">{{date format="DD MMMM YYYY"}}</time>
            </footer>
        </article>
    {{/has}}
{{/foreach}}

1 个答案:

答案 0 :(得分:0)

解决方法是将第一个代码块包装在{{#get}}包装器中,即

{{#get "posts" include="tags,author" filter="featured:true" limit="all" as |featured|}}{{/get}}

下面的主要针脚带有&#34;顶部&#34;标记到Ghost博客的顶部(仅限第1页)并格式化标记为精选的帖子(但没有&#34;顶部&#34;标记),并将其与其他帖子按默认时间顺序包含在内。

https://gist.github.com/anonymous/386c7eb445cc97a45a1ea0ff56898ec6