Handlebar 模板嵌套问题
这个是post-content的代码
<div class="post-content">
<div class="ui grid">
<div class="four wide column">
<a class="avatar"
href="/posts?author={{author._id }}"
data-title="{{author.name }}"
data-content="{{author.bio }}">
<img class="avatar" src="/img/{{author.avatar}}">
</a>
</div>
<div class="eight wide column">
<div class="ui segment">
<h3><a href="/posts/{{_id}}">{{title }}</a></h3>
<pre>{{{content}}}</pre>
<div>
<span class="tag">{{created_at }}</span>
<span class="tag right">
<span>浏览({{ pv }})</span>
<span>留言({{ commentsCount }})</span>
{{#if user}}
<div class="ui inline dropdown">
<div class="text"></div>
<i class="dropdown icon"></i>
<div class="menu">
<div class="item"><a href="/posts/{{_id }}/edit">编辑</a></div>
<div class="item"><a href="/posts/{{_id }}/remove">删除</a></div>
</div>
</div>
{{/if}}
</span>
</div>
</div>
</div>
</div>
</div>
这个是外面的循环posts
{{#each posts}}
{{>post-content}}
{{/each}}
user不是循环里面的东西,数据是posts数组和一个user对象, 在外面的posts模板可以获取到user,里面就获取不到了,怎么样才能去获取
2 回复
../user
放弃这个,用ejs