Ghost handlebars.js {{#has tag="Top"}} 不起作用
Ghost handlebars.js {{#has tag="Top"}} doesn't work
在我的 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}}">»</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}}">»</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}}
解决方案是将第一个代码块包装在 {{#get}}
包装器中,即
{{#get "posts" include="tags,author" filter="featured:true" limit="all" as |featured|}}{{/get}}
下面的要点将带有 "top" 标签的帖子固定到 Ghost 博客的顶部(仅在第 1 页)并将标记为特色的帖子格式化(但没有 "top" 标签)并包含它们与其他帖子按默认时间顺序排列。
https://gist.github.com/anonymous/386c7eb445cc97a45a1ea0ff56898ec6
在我的 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}}">»</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}}">»</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}}
解决方案是将第一个代码块包装在 {{#get}}
包装器中,即
{{#get "posts" include="tags,author" filter="featured:true" limit="all" as |featured|}}{{/get}}
下面的要点将带有 "top" 标签的帖子固定到 Ghost 博客的顶部(仅在第 1 页)并将标记为特色的帖子格式化(但没有 "top" 标签)并包含它们与其他帖子按默认时间顺序排列。
https://gist.github.com/anonymous/386c7eb445cc97a45a1ea0ff56898ec6