0

私の loop.hbs テンプレートでは、Ghost に "Top" というタグが付いた投稿を一番上にピン留めさせようとしています。{{#has}}と組み合わせたヘルパーを使用してい{{#foreach posts}}ます。

以下のコードを参照してください。私が得ている動作は、{{^has tag="Top"}}(つまり、2番目の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}}
4

1 に答える 1

0

解決策は、コードの最初のブロックを{{#get}}ラッパーでラップすることでした。

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

以下の要旨は、「トップ」タグ付きの投稿を Ghost ブログの上部にピン留めし (1 ページのみ)、注目としてマークされた投稿をフォーマットし (ただし「トップ」タグはありません)、デフォルトの時系列順に他の投稿に含めます。

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

于 2016-04-11T00:00:16.603 に答える