E EkoCMS 模板开发手册template · guide
EkoCMS 模板开发手册

交互标签

留言与表单、评论、搜索、分页 / 循环 / 二维码、条件判断。

章节 18–22 返回目录首页

18留言与表单

留言列表 message

参数 / 字段说明
num数量,默认每页条数。
page是否分页,默认开启。
start起始位置。
lg语言过滤,默认当前语言;lg=all 输出所有语言。
[message:contacts]联系人。
[message:mobile]手机号。
[message:content]留言内容。
[message:recontent]回复内容。
[message:askdate]留言时间(映射 create_time)。
[message:replydate]回复时间(映射 update_time)。
[message:ip]提交 IP(映射 user_ip)。
[message:os]操作系统(映射 user_os)。
[message:bs]浏览器(映射 user_bs)。
[message:nickname]会员昵称,未登录时为匿名。
[message:headpic]会员头像。
[message:status]审核状态。
[message:i] / [message:n]序号。

留言表单

留言页通常是「留言栏目」的内容页模板。前台提交到 {eko:msgaction},后台会自动读取留言表单字段。

<form action="{eko:msgaction}" method="post" class="msg-form">
  <input type="text" name="contacts" placeholder="您的称呼" required>
  <input type="tel" name="mobile" placeholder="联系电话">
  <textarea name="content" rows="5" placeholder="留言内容" required></textarea>

  {eko:if({eko:msgcodestatus})}
    <div class="code-row">
      <input type="text" name="checkcode" placeholder="验证码" required>
      <img src="{eko:checkcode}" alt="验证码" onclick="this.src='{eko:checkcode}?'+Math.random()">
    </div>
  {/eko:if}

  <button type="submit">提交留言</button>
</form>

<!-- 留言列表 -->
{eko:message num=10}
  <div class="msg-item">
    <strong>[message:contacts]</strong>
    <time>[message:askdate style=Y-m-d H:i]</time>
    <p>[message:content drophtml=1]</p>
    {eko:if('[message:recontent]'!='')}
      <div class="reply">官方回复:[message:recontent]</div>
    {/eko:if}
  </div>
{/eko:message}

自定义表单

后台「自定义表单」可以创建独立表单(例如报名、预约)。前台用 {eko:form} 输出提交地址,用 {eko:formlist} 读取数据。

标签参数说明
{eko:form fcode=2}fcode 必填输出该表单的提交地址。
{eko:formlist fcode=2 num=10 page=1 start=1}fcode 必填遍历表单提交记录。
<form action="{eko:form fcode=2}" method="post">
  <!-- 字段名必须与后台自定义表单字段名一致 -->
  <input type="text" name="name" placeholder="姓名" required>
  <input type="tel" name="phone" placeholder="电话">
  <select name="course">
    <option value="A">课程 A</option>
    <option value="B">课程 B</option>
  </select>

  {eko:if({eko:formcodestatus})}
    <input type="text" name="checkcode" placeholder="验证码">
    <img src="{eko:checkcode}" alt="验证码">
  {/eko:if}

  <button type="submit">提交报名</button>
</form>

<!-- 读取表单记录:字段名按后台配置直接使用 -->
{eko:formlist fcode=2 num=20}
  <li>
    [form:name] · [form:phone] · [form:course]
    <time>[form:date style=Y-m-d]</time>
  </li>
{/eko:formlist}

表单动态字段直接使用后台字段名,例如 [form:name];提交时间用 [form:date],序号用 [form:i] / [form:n]。

提示

留言与表单都支持频率限制、验证码和登录限制,这些在后台配置。模板侧只需要放对提交地址和验证码开关判断。

19评论

评论标签用于详情页,可按内容 ID 输出评论及子评论。默认模板的 comm/comment.html 是完整参考。

评论列表 comment

参数 / 字段说明
contentid必填,内容 ID。
num数量,默认每页条数。
page是否分页,默认开启。
start起始位置。
order排序,常用 id DESC 或 likes DESC。
[comment:comment]评论内容。
[comment:nickname]评论者昵称。
[comment:headpic]评论者头像。
[comment:date]评论时间。
[comment:ip]评论者 IP 地址。
[comment:os] / [comment:bs]操作系统 / 浏览器。
[comment:likes] / [comment:oppose]点赞 / 反对数。
[comment:pid]父评论 ID。
[comment:pnickname]被回复者昵称。
[comment:pheadpic]被回复者头像。
[comment:replyaction]回复提交地址。
[comment:status]审核状态。
[comment:i] / [comment:n]序号。

子评论 commentsub

在 {eko:comment} 内部使用 {eko:commentsub},字段前缀为 [commentsub:*],字段与主评论一致。

<div class="comment-list">
{eko:comment contentid={content:id} num=10 order='id DESC'}
  <div class="comment" id="comment-[comment:id]">
    <img src="[comment:headpic]" alt="[comment:nickname]">
    <div class="c-main">
      <strong>[comment:nickname]</strong>
      <time>[comment:date style=Y-m-d H:i]</time>
      <p>[comment:comment drophtml=1]</p>
      <a href="[comment:replyaction]">回复</a>

      {eko:commentsub num=5}
        <div class="comment-sub">
          <strong>[commentsub:nickname]</strong>
          <span>回复 [commentsub:pnickname]:</span>
          <p>[commentsub:comment drophtml=1]</p>
        </div>
      {/eko:commentsub}
    </div>
  </div>
{/eko:comment}
</div>

<!-- 评论提交表单:commentaction 已自动带上 contentid -->
<form action="{eko:commentaction}" method="post">
  <textarea name="comment" required></textarea>
  {eko:if({eko:commentcodestatus})}
    <input type="text" name="checkcode" placeholder="验证码">
    <img src="{eko:checkcode}" alt="验证码">
  {/eko:if}
  <button type="submit">发表评论</button>
</form>

我的评论 mycomment

在会员中心使用,只输出当前登录会员的评论。字段与评论一致,并额外提供文章标题与删除地址。

{eko:mycomment num=10 page=1}
  <li>
    <strong>[mycomment:title]</strong>
    <p>[mycomment:comment drophtml=1]</p>
    <time>[mycomment:date style=Y-m-d H:i]</time>
    <a href="[mycomment:delaction]" onclick="return confirm('确定删除?')">删除</a>
  </li>
{/eko:mycomment}
字段说明
[mycomment:title]评论所属内容标题。
[mycomment:status]审核状态。
[mycomment:delaction]删除评论地址。
其余字段与 [comment:*] 一致。
注意

评论内容由用户提交,展示时建议加 drophtml=1,避免富文本 / 脚本注入。评论功能开关、验证码、审核状态在后台配置。

21分页 / 循环 / 二维码

分页标签

分页变量由带分页的列表(list / search / comment / message 等)生成,之后用 {page:*} 输出。

标签输出
{page:bar}完整分页条 HTML,含首页、上一页、数字、下一页、尾页。
{page:current}当前页码。
{page:count}总页数。
{page:rows}总记录数。
{page:index}首页地址。
{page:pre}上一页地址。
{page:next}下一页地址。
{page:last}尾页地址。
{page:status}状态文本,例如「共120条 当前1/12页」。
{page:numbar}数字页码部分。
{page:selectbar}页码下拉选择。

默认分页条结构

<span class="page-status">共120条 当前1/12页</span>
<span class="page-index"><a href="...">首页</a></span>
<span class="page-pre"><a href="...">前一页</a></span>
<span class="page-numbar">
  <a class="page-num page-num-current">1</a>
  <a class="page-num" href="...">2</a>
</span>
<span class="page-next"><a href="...">后一页</a></span>
<span class="page-last"><a href="...">尾页</a></span>

可以直接用这些 class 写样式;没有数据时 {page:bar} 输出 page-none 提示。需要自定义结构时,用 {page:pre}、{page:next}、{page:numbar} 等单独组合;{page:selectbar} 不在默认分页条中。

循环 loop

纯数字循环,不查数据库,适合输出评分星、占位块等。

<!-- 输出 1 到 5 -->
{eko:loop start=1 end=5}
  <i class="star">[loop:i]</i>
{/eko:loop}

<!-- 输出序号与当前值 -->
{eko:loop start=3 end=6}
  <span data-n="[loop:n]">第 [loop:i] 次 / 当前值 [loop:index]</span>
{/eko:loop}
参数 / 字段说明
start起始值,默认 1;小于 1 时按 1 处理。
end结束值(包含),默认每页条数。
[loop:i]循环序号,从 1 开始。
[loop:n]循环序号,从 0 开始。
[loop:index]当前循环值,从 start 到 end。

单次最多循环 1000 次;start 最小为 1,不能从 0 开始。

二维码 qrcode

<div class="qr">
  {eko:qrcode string={eko:httpurl}{URL}}
  <p>扫码在手机上打开</p>
</div>

<!-- 指定任意内容 -->
{eko:qrcode string='https://www.example.com'}

输出一个 <img class="qrcode">,地址指向核心二维码接口。{eko:httpurl} 是当前域名,{URL} 是当前路径常量,两者拼接即可生成当前页二维码。

22条件判断

{eko:if} 在数据标签替换之后执行,因此条件里可以直接使用 [list:field]、{sort:scode} 等标签。

基础语法

{eko:if([list:istop]==1)}
  <span class="badge">置顶</span>
{/eko:if}

{eko:if('[list:title]'!='')}
  <h3>[list:title]</h3>
{else}
  <h3>未命名</h3>
{/eko:if}

{eko:if('[list:date]'>='2025-01-01' && [list:istop]==1)}
  <span>2025 年置顶</span>
{/eko:if}

支持的运算符

类别运算符
比较==、!=、>、<、>=、<=
逻辑&&(且)、||(或)

限制

  • 不能使用 PHP 变量:条件中不允许出现 $,例如 {eko:if($x==1)} 无效。
  • 不能调用任意函数:仅允许 date('格式'),会在比较前替换为当前日期。
  • 标签值要加引号:比较文本时写成 '[list:title]'=='产品',避免标题中出现空格导致解析错误。
  • 逻辑运算只支持一层:一个条件里只能出现一个 && 或 ||,且只比较左右两段;不要使用括号、取反或取模运算,复杂判断用嵌套 {eko:if}。
  • 条件中不要出现 }:它会被误认为标签结束。

嵌套判断

嵌套时使用数字前缀:第二层写 {eko:2if}、{2else}、{/eko:2if};第三层依次类推。

{eko:if([list:ispics]==1)}
  <span>多图</span>

  {eko:2if([list:isrecommend]==1)}
    <span>推荐 + 多图</span>
  {2else}
    <span>仅多图</span>
  {/eko:2if}

{else}
  <span>普通内容</span>
{/eko:if}

常用判断

<!-- 是否登录 -->
{eko:if({eko:islogin}==1)} 已登录 {else} 未登录 {/eko:if}

<!-- 是否有缩略图 -->
{eko:if([list:isico]==1)}
  <img src="[list:ico]" alt="[list:title]">
{/eko:if}

<!-- 是否外链 -->
{eko:if('[list:outlink]'!='')}
  <a href="[list:outlink]" target="_blank">[list:title]</a>
{else}
  <a href="[list:link]">[list:title]</a>
{/eko:if}

<!-- 当前栏目 -->
{eko:if('[sort:scode]'=='2')}
  <body class="is-product">
{else}
  <body>
{/eko:if}
建议

如果是「按会员等级 / 登录状态显示」的需求,优先使用上一章的权限参数,比手写 {eko:if} 更简洁,也更安全。