高安全性的内容管理系统
一站式建站解决方案
高性能静态网站构建工具
精美的网站模板库
详细的模板开发指南
完整的API接口说明
直观的视频使用指南
常见问题解答集锦
最新产品动态与行业资讯
了解我们的故事
获取支持与合作
说明:用于获取文档的评论列表、评论分页列表
使用方法:{% commentList 变量名称 with archiveId="1" type="page|list" %} 如将变量定义为 comments {% commentList comments with archiveId="1" type="page" %}...{% endcommentList %}
{% commentList 变量名称 with archiveId="1" type="page|list" %}
{% commentList comments with archiveId="1" type="page" %}...{% endcommentList %}
archiveId
order
order="id desc"
limit
limit="10"
offset
,
limit="2,10"
type
type="page"
pagination
{% pagination pages with show="5" %}
siteId
comments 是一个数组对象,因此需要使用 for 循环来输出
for
Id
ArchiveId
UserName
UserId
Ip
VoteCount
Content
ParentId
Status
Parent
CreatedTime
{{stampToDate(item.CreatedTime, "2006-01-02")}}
{# list 列表展示 #} <div> {% commentList comments with archiveId=archive.Id type="list" limit="6" %} {% for item in comments %} <div> <div> <span> {% if item.Status != 1 %} 审核中:{{item.UserName|truncatechars:6}} {% else %} {{item.UserName}} {% endif %} </span> {% if item.Parent %} <span>回复</span> <span> {% if item.Status != 1 %} 审核中:{{item.Parent.UserName|truncatechars:6}} {% else %} {{item.Parent.UserName}} {% endif %} </span> {% endif %} <span>{{stampToDate(item.CreatedTime, "2006-01-02")}}</span> </div> <div> {% if item.Parent %} <blockquote> {% if item.Parent.Status != 1 %} 该内容正在审核中:{{item.Parent.Content|truncatechars:9}} {% else %} {{item.Parent.Content|truncatechars:100}} {% endif %} </blockquote> {% endif %} {% if item.Status != 1 %} 该内容正在审核中:{{item.Content|truncatechars:9}} {% else %} {{item.Content}} {% endif %} </div> <div class="comment-control" data-id="{{item.Id}}" data-user="{{item.UserName}}"> <a class="item" data-id="praise">赞(<span class="vote-count">{{item.VoteCount}}</span>)</a> <a class="item" data-id=reply>回复</a> </div> </div> {% endfor %} {% endcommentList %} </div>
{# page 分页列表展示 #} <div> {% commentList comments with archiveId=archive.Id type="page" limit="10" %} {% for item in comments %} <div> <div> <span> {% if item.Status != 1 %} 审核中:{{item.UserName|truncatechars:6}} {% else %} {{item.UserName}} {% endif %} </span> {% if item.Parent %} <span>回复</span> <span> {% if item.Status != 1 %} 审核中:{{item.Parent.UserName|truncatechars:6}} {% else %} {{item.Parent.UserName}} {% endif %} </span> {% endif %} <span>{{stampToDate(item.CreatedTime, "2006-01-02")}}</span> </div> <div> {% if item.Parent %} <blockquote> {% if item.Parent.Status != 1 %} 该内容正在审核中:{{item.Parent.Content|truncatechars:9}} {% else %} {{item.Parent.Content|truncatechars:100}} {% endif %} </blockquote> {% endif %} {% if item.Status != 1 %} 该内容正在审核中:{{item.Content|truncatechars:9}} {% else %} {{item.Content}} {% endif %} </div> <div class="comment-control" data-id="{{item.Id}}" data-user="{{item.UserName}}"> <a class="item" data-id="praise">赞(<span class="vote-count">{{item.VoteCount}}</span>)</a> <a class="item" data-id=reply>回复</a> </div> </div> {% endfor %} {% endcommentList %} </div> <div> {% pagination pages with show="5" %} <ul> <li>总数:{{pages.TotalItems}}条,总共:{{pages.TotalPages}}页,当前第{{pages.CurrentPage}}页</li> <li class="{% if pages.FirstPage.IsCurrent %}active{% endif %}"><a href="{{pages.FirstPage.Link}}">{{pages.FirstPage.Name}}</a></li> {% if pages.PrevPage %} <li><a href="{{pages.PrevPage.Link}}">{{pages.PrevPage.Name}}</a></li> {% endif %} {% for item in pages.Pages %} <li class="{% if item.IsCurrent %}active{% endif %}"><a href="{{item.Link}}">{{item.Name}}</a></li> {% endfor %} {% if pages.NextPage %} <li><a href="{{pages.NextPage.Link}}">{{pages.NextPage.Name}}</a></li> {% endif %} <li class="{% if pages.LastPage.IsCurrent %}active{% endif %}"><a href="{{pages.LastPage.Link}}">{{pages.LastPage.Name}}</a></li> </ul> {% endpagination %} </div>
评论使用 form 表单提交,提交后台接收的地址为:/comment/publish 。需要提交的字段有
/comment/publish
html
json
表单代码示例
<form method="post" action="/comment/publish"> <input type="hidden" name="return" value="html"> <input type="hidden" name="archive_id" value="{% archiveDetail with name="Id" %}"> <div> <label>用户名</label> <div> <input type="text" name="user_name" required lay-verify="required" placeholder="请填写您的昵称" autocomplete="off"> </div> </div> <div> <label>评论内容</label> <div> <textarea name="content" placeholder="" id="comment-content-field" rows="5"></textarea> </div> </div> <div> <div> <button type="submit">提交评论</button> <button type="reset">重置</button> </div> </div> </form>
可以给某条评论的内容点赞,点赞使用 form 表单提交,点赞提交后台接收地址为:/comment/praise 。点赞需要提交的字段有:
/comment/praise
评论点赞只支持返回 json 格式的数据,因此需要用 js post 来提交。
示例代码
<div class="comment-control"> <a class="item vote-comment" data-id="praise" data-id="{{item.Id}}">赞(<span class="vote-count">{{item.VoteCount}}</span>)</a> </div>
$(".vote-comment").click(function (e) { let that = $(this); let commentId = $(this).data("id"); //赞 $.ajax({ url: "/comment/praise", method: "post", data: { id: commentId }, dataType: "json", success: function (res) { if (res.code === 0) { alert(res.msg); that.find(".vote-count").text(res.data.vote_count); } else { alert(res.msg); } }, error: function (err) { alert(res.msg); }, }); });