xiaosongshu1911
V2EX  ›  Node.js

问一下 ejs 改写 swig 的问题

  •  
  •   xiaosongshu1911 · Dec 28, 2015 · 3305 views
    This topic created in 3867 days ago, the information mentioned may be changed or developed.

    <% 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 replies    2015-12-28 21:28:35 +08:00
    xiaosongshu1911
        1
    xiaosongshu1911  
    OP
       Dec 28, 2015
    <% 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
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1635 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 16:19 · PVG 00:19 · LAX 09:19 · JFK 12:19
    ♥ Do have faith in what you're doing.