下划线模板:部分或包含
我正在使用 underscore 模板在客户端渲染 html。我正在构建一个新闻提要,其中包含不同类型的新提要项目,每个项目都需要不同的模板。问题是他们都在每个提要项目的底部共享相同的评论区域。因此,我只想对此进行一次模板化,但将其呈现在每个单独的 feeditem 模板中。
在每个提要项目中包含评论而不在每个提要项目模板中复制评论模板的最佳方式是什么?我应该在主模板外部运行评论模板并在其后附加 html 吗?
I am using underscore templating to render html on the client side. I am constructing a news feed which contains different types of new feed items that each require a different template. The thing is they all share the same Comments area at the bottom of each feed item. I would therefore only like to template this once but have it rendered in each of the seperate feeditem templates.
What is the best way of including comments inside each feed item without duplicating the comments template inside each of the feed item templates? Should I just run the comments template outside of the main template and append the html after?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将评论模板分开是明智的,特别是考虑到您应该有一个评论模型和集合。最好的想法是让每个模板包含类似
的内容。然后在你的backbone.js视图中,你可以有这样的东西:
It would be smart to keep the comment template separate, especially considering you should have a model and collection for the comments. The best idea would be to have each template include something like
<div class="comments-section"></div>
. Then in your backbone.js view, you could have something like this: