【发布时间】:2014-11-10 23:12:38
【问题描述】:
目前正在使用 Ghost CMS 建立一个简单的站点。默认情况下,主页带有一个通过foreach 循环检索的帖子列表。我正在尝试在帖子页面上重新创建它,但没有任何内容被拉入。
文件结构为:
/theme
/theme/index.hbs
/theme/post.hbs
index.hbs 上的代码是:
{{#foreach posts}}
<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 image" 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>
{{/foreach}}
我在post.hbs 页面上使用的稍微精简的版本是:
<aside class="timeline">
{{#foreach posts}}
<h4 class="post-title"><a href="{{url}}">{{{title}}}</a></h4>
<section class="post-meta">
{{author}}
{{tags prefix=" on "}}
<time class="post-date" datetime="{{date format='YYYY-MM-DD'}}">{{date format="DD MMMM YYYY"}}</time>
</section>
{{/foreach}}
</aside>
我的猜测是我不能在帖子页面上调用帖子,但我不确定。
【问题讨论】:
-
不是 100% 确定 ghost 是如何工作的,但我对车把的正常操作是我的 js 获取数据然后将其传递给车把模板,你的问题的措辞方式似乎你期望车把模板自己发布帖子,有点像 wordpress 的做法
-
相信你猜对了。您不能在
post.hbs上致电posts。您可以使用 RSS 提要通过 javascript 生成列表吗?
标签: javascript handlebars.js ghost-blog