首页 > 解决方案 > 如何在 PUG 中实现 EJS 模板?

问题描述

有人可以帮我将此 EJS 代码转换为 PUG 吗?我正在尝试学习 PUG,我想实现这段代码;是为了分页。在 EJS 中一切正常,但我还没有完全掌握如何在 PUG 中编写条件和循环。以下是代码片段:

</div>
  <% if (pages > 0) { %>
      <ul class="pagination text-center">
          <% if (current == 1) { %>
              <li class="disabled"><a>First</a></li>
          <% } else { %>
              <li><a href="/products/1">First</a></li>
          <% } %>
          <% var i = (Number(current) > 5 ? Number(current) - 4 : 1) %>
          <% if (i !== 1) { %>
              <li class="disabled"><a>...</a></li>
          <% } %>
          <% for (; i <= (Number(current) + 4) && i <= pages; i++) { %>
              <% if (i == current) { %>
                  <li class="active"><a><%= i %></a></li>
              <% } else { %>
                  <li><a href="/products/<%= i %>"><%= i %></a></li>
              <% } %>
              <% if (i == Number(current) + 4 && i < pages) { %>
                  <li class="disabled"><a>...</a></li>
              <% } %>
          <% } %>
          <% if (current == pages) { %>
              <li class="disabled"><a>Last</a></li>
          <% } else { %>
              <li><a href="/products/<%= pages %>">Last</a></li>
          <% } %>
      </ul>
  <% } %>
</div>

我所做的所有研究都指向 HTML 到 EJS 或 HTML 到 PUG,反之亦然。任何帮助都感激不尽。

标签: node.jsexpresspugejs

解决方案


推荐阅读