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

附录

字段速查、实战示例、常见问题与标签索引。

章节 23–26 返回目录首页

23字段速查

除了前面按标签列出的字段,这里补充各数据表的核心字段,方便在后台核对或直接使用未列出的字段。

数据表对照

数据表对应标签核心字段
ek_site{eko:site*}acode, title, subtitle, domain, logo, keywords, description, icp, theme, statistical, copyright
ek_company{eko:company*}name, address, postcode, contact, mobile, phone, fax, email, qq, weixin, blicense, other
ek_content_sort{eko:nav} / {eko:sort} / {sort:*}id, acode, mcode, pcode, scode, name, subname, listtpl, contenttpl, status, outlink, ico, pic, title, keywords, description, filename, sorting, gtype, gid, gnote, def1-3
ek_content{eko:list} / [content:*]id, acode, scode, subscode, title, subtitle, titlecolor, filename, author, source, outlink, date, ico, pics, picstitle, content, tags, enclosure, keywords, description, sorting, status, istop, isrecommend, isheadline, visits, likes, oppose, gtype, gid, gnote, contenttpl, create_time, update_time
ek_content_ext[list:ext_*]动态扩展字段,字段名以 ext_ 开头,跟随内容模型。
ek_slide{eko:slide}id, acode, gid, pic, link, title, subtitle, sorting
ek_link{eko:link}id, acode, gid, name, link, logo, sorting
ek_message{eko:message}id, acode, contacts, mobile, content, user_ip, user_os, user_bs, recontent, status, uid, create_time, update_time
ek_member_comment{eko:comment}id, pid, contentid, comment, uid, puid, likes, oppose, status, user_ip, user_os, user_bs, create_time, update_time
ek_member{user:*}id, username, nickname, headpic, usermobile, useremail, sex, birthday, qq, score, gcode, status, register_time, login_count, last_login_ip, last_login_time
自定义表单表{eko:formlist}由后台「自定义表单」动态创建,字段名与表单配置一致。

栏目类型与模板字段

字段说明
listtpl栏目列表页模板,如 newslist.html。
contenttpl栏目内容页 / 单页模板,如 news.html、about.html。
outlink栏目外链;设置后栏目链接会直接指向该地址。
filename自定义 URL 文件名(伪静态时使用)。
gtype / gid / gnote访问权限类型 / 等级 / 提示文字。
def1 / def2 / def3栏目预留自定义字段。

扩展字段

内容模型可以添加扩展字段,字段名必须以 ext_ 开头。添加后可以在以下位置使用:

[list:ext_xxx] [content:ext_xxx] [search:ext_xxx] filter='ext_xxx|值' order=ext_xxx DESC {eko:select field=ext_xxx} {eko:checkbox field=ext_xxx}

扩展字段值会随内容一起输出;多选字段用 {eko:checkbox} 展开,多图字段用 {eko:pics field=ext_xxx} 展开。

24实战示例

以下示例省略了样式,只保留模板结构与标签,可直接作为新模板的起点。

首页 index.html

{include file=comm/head.html}
{include file=comm/top.html}

<main>
  <!-- 首屏轮播 -->
  <div class="banner">
  {eko:slide gid=1 num=5}
    <a href="[slide:link]">
      <img src="[slide:src maxwidth=1920]" alt="[slide:title]">
      <div class="caption">
        <h2>[slide:title]</h2>
        <p>[slide:subtitle]</p>
      </div>
    </a>
  {/eko:slide}
  </div>

  <!-- 最新动态 -->
  <section class="block">
    <div class="block-head">
      <h2>最新动态</h2>
    </div>
    <div class="news-grid">
    {eko:list scode=2 num=6 page=0 order='istop DESC,date DESC'}
      <article>
        <a href="[list:link]">
          {eko:if([list:isico]==1)}
            <img src="[list:ico maxwidth=640]" alt="[list:title]">
          {/eko:if}
          <h3>[list:title lencn=26]</h3>
          <p>[list:description len=70]</p>
          <time>[list:date style=Y-m-d]</time>
        </a>
      </article>
    {/eko:list}
    </div>
  </section>

  <!-- 产品中心 -->
  <section class="block">
    <h2>产品中心</h2>
    <div class="product-grid">
    {eko:list scode=3 num=8 page=0 order=sorting}
      <a href="[list:link]">
        <img src="[list:ico maxwidth=500]" alt="[list:title]">
        <h3>[list:title]</h3>
      </a>
    {/eko:list}
    </div>
  </section>

  <!-- 公司简介:读取单页内容 -->
  {eko:content scode=1}
  <section class="block about">
    <div class="about-text">
      <h2>[content:title]</h2>
      <div>[content:content]</div>
      <a href="[content:link]">了解更多</a>
    </div>
    <img src="[content:ico maxwidth=800]" alt="[content:title]">
  </section>
  {/eko:content}
</main>

{include file=comm/foot.html}

列表页 newslist.html

{include file=comm/head.html}
{include file=comm/top.html}

<div class="page-banner" style="background-image:url('{sort:pic maxwidth=1920}')">
  <h1>{sort:name}</h1>
  <p>{sort:description}</p>
</div>

{include file=comm/position.html}

<main class="page-wrap">
  <div class="filter-bar">
    {eko:selectall field=ext_type text='全部' class='chip' active='chip-on'}
    {eko:select field=ext_type}
      <a href="[select:link]" class="chip {eko:if('[select:value]'=='[select:current]')}chip-on{/eko:if}">[select:value]</a>
    {/eko:select}
  </div>

  <div class="news-list">
  {eko:list num=12 order='istop DESC,date DESC'}
    <article class="news-item">
      <a class="thumb" href="[list:link]">
        <img src="[list:ico maxwidth=480]" alt="[list:title]">
      </a>
      <div class="info">
        <h3><a href="[list:link]">[list:title]</a></h3>
        <p>[list:content drophtml=1 dropblank=1 len=120]</p>
        <div class="meta">
          <time>[list:date style=Y-m-d]</time>
          <span>[list:visits] 阅读</span>
        </div>
      </div>
    </article>
  {/eko:list}
  </div>

  {eko:if({page:rows}>0)}
    {include file=comm/page.html}
  {else}
    <p class="empty">该栏目暂无内容</p>
  {/eko:if}
</main>

{include file=comm/foot.html}

详情页 news.html

{include file=comm/head.html}
{include file=comm/top.html}

{include file=comm/position.html}

<main class="article-wrap">
  <article>
    <h1>[content:title]</h1>
    <div class="meta">
      <a href="[content:sortlink]">[content:sortname]</a>
      <time>[content:date style=Y-m-d H:i]</time>
      <span>[content:visits] 阅读</span>
      <span>[content:author]</span>
    </div>

    <div class="article-body">[content:content]</div>

    {eko:if('[content:tags]'!='')}
      <div class="article-tags">
      {eko:tags id={content:id} scode={sort:tcode} target=tag}
        <a href="[tags:link]"># [tags:text]</a>
      {/eko:tags}
      </div>
    {/eko:if}

    <div class="prev-next">
      <a href="[content:prelink]">上一篇:[content:pretitle]</a>
      <a href="[content:nextlink]">下一篇:[content:nexttitle]</a>
    </div>
  </article>

  <!-- 相关阅读:同栏目,排除当前文章 -->
  <aside class="related">
    <h3>相关阅读</h3>
    {eko:list scode={sort:scode} num=5 page=0 order=visits DESC}
      <a href="[list:link]">[list:title lencn=26]</a>
    {/eko:list}
  </aside>

  {include file=comm/comment.html}
</main>

{include file=comm/foot.html}
注意

「相关阅读」中的 {eko:list} 必须显式写 scode 并加 page=0:详情页没有「当前栏目列表」上下文,省略 scode 的列表不会被解析,而分页列表还会覆盖评论等其他分页参数。上面示例未排除当前文章,需要精确排除时建议用后台标签或单独的筛选条件。

25常见问题

标签没有解析,原样显示了

  • 确认文件位于 template/{主题}/html/ 下,并且是通过栏目 / 页面正常访问的模板,而不是被当作静态文件直接打开。
  • 确认标签拼写正确,CMS 标签必须带 {eko: 前缀,关闭标签为 {/eko:xxx}。
  • 清空 runtime/complile 与 runtime/cache,或在后台清除缓存。
  • 如果内容是富文本里写的标签,内容区的标签默认不会被二次解析,这是安全设计。

{eko:if} 条件不生效

  • 条件内不能出现 $、函数调用或 };只能使用标签值和 date('格式')。
  • 比较文本时给标签值加引号:'[list:title]'=='产品'。
  • 多个条件建议只用一个 && 或 ||,复杂逻辑用嵌套 {eko:2if}。
  • 条件是在数据替换后执行的,必须把 {eko:if} 放在对应的 {eko:list} 内部才能读取 [list:*]。

分页错乱或第二页没有数据

  • 一个页面只能有一个分页列表。其他列表全部加 page=0。
  • 指定 scode 的列表默认不分页;需要分页时加 page=1。
  • 分页标签必须放在分页列表之后,否则变量还未生成。
  • 搜索 / 评论 / 留言也各自维护分页变量,同一页不要混用多个分页数据源。

列表为空或字段不输出

  • 检查栏目 scode 是否正确;scode=* 表示全站。
  • 检查内容是否已发布、是否属于该栏目、是否被权限等级限制。
  • [list:*] 必须写在 {eko:list} 内部,写在外部不会解析。
  • 使用了 lfield 限制字段时,未列出的字段不会返回。
  • 字段名写错时会输出空字符串;先在后台确认字段名。

filter 筛选没有效果

  • 字段必须在白名单内;普通内容字段和 ext_ 字段可用,其他表字段不可用。
  • 一个标签只保留最后一个 filter 参数,不能写多个。
  • 多个值用逗号表示 OR;需要 AND 时拆成多个列表块。
  • 文本模糊匹配要加 fuzzy=1,默认是精确匹配。

图片没有按尺寸输出

  • 只有站内上传的图片会走裁剪 / 缩放;外链图片原样输出。
  • 检查图片字段是否有值,空值不会生成占位图。
  • 首次访问会生成缓存,确认 runtime/image/ 可写。

自定义表单提交后没有数据

  • 表单字段名必须与后台自定义表单的字段名完全一致。
  • 提交地址必须是 {eko:form fcode=编号},编号对应后台表单。
  • 如果开启了验证码,表单必须包含 checkcode 输入框,并用 {eko:formcodestatus} 判断是否显示。
  • 后台查看表单记录时注意筛选表单编号。

{user:*} 输出为空

  • 会员标签只在登录后输出;未登录时为空,先用 {eko:islogin} 判断。
  • 字段名必须存在;password 永远不输出。
  • 会员中心模板需要先放 {eko:mustlogin} 或在后台限制访问。

包含文件报错或死循环

  • 检查 {include} 路径是否相对于主题 html/ 目录。
  • 包含最多 50 层,避免 A 包含 B、B 又包含 A。
  • 包含在编译阶段执行,路径不能使用变量或 CMS 标签。

修改模板后页面没变化

  • 页面 HTML 缓存开启时,未登录访问会命中旧缓存;登录后预览或清理缓存。
  • 检查是否改到了另一个主题目录(多语言 / 移动端可能使用不同主题)。
  • 确认浏览器没有缓存 CSS / JS;静态资源可加版本参数。

链接写死域名后换域名失效

  • 站内链接优先使用 [list:link]、[sort:link]、{eko:siteindex} 等标签。
  • 静态资源使用 {eko:sitepath} 或 {eko:sitetplpath} 前缀。
  • 不要在多语言站点写死某一种语言的 URL。

评论 / 留言内容出现脚本

  • 展示用户提交内容时加 drophtml=1,必要时用 {fun=htmlspecialchars(...)} 转义。
  • 后台开启审核与验证码,减少垃圾内容。
  • 富文本正文由系统过滤,但仍建议只信任可信编辑者。

如何显示模板标签本身

用 {eko:pre}...{/eko:pre} 包裹即可,内容不会被解析。适合教程、帮助中心、代码示例页。

如何调试某个字段的值

临时在模板中输出 [list:字段],或使用 {fun=var_dump($变量)}(仅限开发环境,调试后立即删除)。生产环境不要保留调试输出。

26标签索引

按标签首字母 / 类型快速定位,参数与字段详见对应章节。

数据块标签

标签作用域核心参数章节
{eko:nav}[nav:*]num, parent, scode导航与栏目
{eko:sort}[sort:*]scode(必填)栏目块
{eko:list}[list:*]scode, num, order, filter, fuzzy, tags, page, start, lfield内容列表
{eko:content}[content:*]id, scode内容详情
{eko:pics}[pics:*]id(必填), field, num多图
{eko:checkbox}[checkbox:*]id(必填), field(必填)多选
{eko:tags}[tags:*]id, scode, num, targetTags
{eko:slide}[slide:*]gid, num, start幻灯片
{eko:link}[link:*]gid, num, start友链
{eko:message}[message:*]num, page, start, lg留言
{eko:formlist}[form:*]fcode(必填), num, page, start自定义表单
{eko:comment}[comment:*]contentid(必填), num, page, start, order评论
{eko:mycomment}[mycomment:*]num, page, start, order我的评论
{eko:search}[search:*]field, scode, num, order, fuzzy, page搜索
{eko:select}[select:*]field(必填)筛选
{eko:loop}[loop:*]start, end循环
{eko:if}—条件表达式条件判断
{eko:pre}—无保护标签

单标签

分组标签章节
站点{eko:sitetitle}、{eko:sitelogo}、{eko:sitekeywords}、{eko:siteindex}、{eko:sitepath}、{eko:sitetplpath} 等站点与公司
公司{eko:companyname}、{eko:companyaddress}、{eko:companymobile} 等站点与公司
会员{eko:login}、{eko:register}、{eko:ucenter}、{eko:logout}、{eko:islogin}、{eko:mustlogin}系统单标签
验证码{eko:checkcode}、{eko:msgcodestatus}、{eko:formcodestatus}、{eko:commentcodestatus}系统单标签
SEO{eko:pagetitle}、{eko:pagekeywords}、{eko:pagedescription}、{eko:keyword}系统单标签
URL{eko:httpurl}、{eko:pageurl}、{eko:msgaction}、{eko:scaction}、{eko:commentaction}系统单标签
自定义{label:标签名}自定义标签
会员资料{user:字段}会员标签
当前位置{eko:position}当前位置
筛选全部{eko:selectall}筛选
二维码{eko:qrcode}二维码
分页{page:bar}、{page:current}、{page:rows}、{page:pre}、{page:next} 等分页

框架语法

语法用途章节
{include file=...}包含模板片段框架基础语法
{$var} / {$obj->prop}输出变量框架基础语法
{if(...)}...{else}...{/if}框架级条件框架基础语法
{foreach $arr(k,v,i)}...{/foreach}框架级循环框架基础语法
{url.*} / {homeurl.*}生成 URL框架基础语法
{fun=...}调用函数并输出框架基础语法
{php}...{/php}原生 PHP(谨慎)框架基础语法