问一下 ejs 改写 swig 的问题

2015-12-28 21:04:36 +08:00
 xiaosongshu1911

<% if (pagination == 2){ %>
<% page.posts.each(function(item){ %>
<%- partial('article', {item: item, index: true}) %>
<% }); %>

<%- partial('pagination') %>
<% } else { %>
<!-- Height spacing helper -->
<div class="heightblock"></div>
<!-- // End height spacing helper -->
<section id="services">
<div class="container">
<div class="row">
<div class="col-md-2">
<div class="row">
<h3><%= title %></h3>
<% if (page.category){ %>
<a href="<%- config.root %>categories"><< 返回标签列表</a>
<% }%>
<% if (page.tag){ %>
<a href="<%- config.root %>categories"><< 返回标签列表</a>
<% }%>
<% if (page.archive){ %>
<%- list_archives() %>
<% }%>
</div>
</div>
<div class="col-md-9 col-md-offset-1">
<div class="row">
<% var i=0 %>
<% page.posts.each(function(item){ %>
<% if(i==4){ %>
</div><div class="row boxes">
<% i=0 %>
<% } %>
<% i++ %>
<div class="col-xs-12 col-sm-3 col-md-3 col-lg-3 wow fadeInUp" data-wow-delay="0.3s">
<% if (item.link){ %>
<% if (item.title){ %>
<h4 class="title link"><a href="<%- item.link %>" target="_blank"><%= item.title %></a></h4>
<% } else { %>
<h4 class="title link"><a href="<%- item.link %>" target="_blank"><%= item.link %></a></h4>
<% } %>
<% } else { %>
<h4 class="title"><a href="<%- config.root %><%- item.path %>"><%= item.title %></a></h4>
<% } %>
<p><time datetime="<%= item.date.toDate().toISOString() %>"><a href="<%- config.root %><%- item.path %>"><%= item.date.format(config.date_format) %></a></time></p>
</div>
<% }); %>
</div>
</div>

</div>
</div>
</section>
<% } %>

这一段时 ejs 写的,我想改写成 swig ,请问怎么写,主要是里面的 each 循环不会写

2796 次点击
所在节点    Node.js
1 条回复
xiaosongshu1911
2015-12-28 21:28:35 +08:00
<% site.posts.sort('date', -1).limit(5).each(function(post){ %>
<li>
<a href="<%- url_for(post.path) %>"><%= post.title || '(no title)' %></a>
</li>
<% }) %>

hexo 主题用 ejs 写的,我想改成 nunjucks 模板引擎,请问上面这段循环怎么用 nunjucks 写,我看了下官网,好象没有 each 循环

https://mozilla.github.io/nunjucks/cn/templating.html

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/246768

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX