node.js - 如何在 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,反之亦然。任何帮助都感激不尽。
解决方案
推荐阅读
- snowflake-cloud-data-platform - 连接到 Snowflake 时如何解决 C# 中的无效 URI 问题?
- azure - 客户订阅(即订阅者)某个主题的生命周期是多少?
- angular - 将新数组元素添加到表单时,自定义组件 FormControl 出错
- javascript - 如何在发送 Nest.js 之前格式化响应?
- swift - Swift - 将 cURL 转换为 Swift 请求
- node.js - 使用无服务器框架时从 AWS Lambda 函数连接 AWS ElasticSearch 实例时出错
- c# - c# UDPClient.Receive 随机不接收数据包
- json - 如何在使用 Spring Boot 的 REST API 构建中本地化域对象的各个值?
- typescript - Sequelize findAll() without where 子句返回的行数少于数据库中的 SELECT COUNT
- c# - Animator.SetBool() 中断 NavMeshAgent