V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
xiaosongshu1911
V2EX  ›  Node.js

问一下 ejs 改写 swig 的问题

  •  
  •   xiaosongshu1911 · 2015-12-28 21:04:36 +08:00 · 2791 次点击
    这是一个创建于 3044 天前的主题,其中的信息可能已经有所发展或是发生改变。

    <% 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 循环不会写

    1 条回复    2015-12-28 21:28:35 +08:00
    xiaosongshu1911
        1
    xiaosongshu1911  
    OP
       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
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   987 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 19:23 · PVG 03:23 · LAX 12:23 · JFK 15:23
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.