页面速查
TanzCMS 官方文档示例,展示模板标签、开放 API、内容管理和部署说明。
模板制作指南
本文面向主题制作者,汇总 TanzCMS 当前可用的模板写法。
页面类型
常用模板文件:
index.html:首页。list.html:栏目/列表页。category.html、category_*.html:栏目封面页,用于存在下级栏目的列表栏目。show.html:内容详情页。page.html、page_*.html:单页模板。list_*.html:栏目列表扩展模板。show_*.html:内容详情扩展模板。search.html:搜索页。header.html、footer.html:公共头尾。member/index.html:会员中心首页。
通用写法
{template "header.html"}
{template "footer.html"}
变量输出:
{$title}
{$content}
{$published_at}
条件和循环:
{if $thumb}
{thumb_img url=$thumb width=300 height=200 alt=$title}
{/if}
{loop $items $item}
{$item.title}
{/loop}
首页
普通内容列表:
{content model=article num=10 order=updatetime}
<a href="{$t.url}">{$t.title}</a>
{/content}
带缩略图列表:
{content model=article num=6 order=updatetime}
<article>
<a href="{$t.url}">{if $t.thumb}{thumb_img url=$t.thumb width=240 height=160 alt=$t.title}{/if}</a>
<h3><a href="{$t.url}">{$t.title}</a></h3>
<p>{$t.description}</p>
</article>
{empty}
<p>暂无内容</p>
{/empty}
{/content}
置顶优先:
{content model=article num=6 order=top}
<a href="{$t.url}">{$t.title}</a>
{/content}
栏目/列表
栏目标题和描述:
<h1>{$category.name}</h1>
<div class="category-description">{$category.description}</div>
当前栏目分页列表:
{content model=article catid=$catid page=1 pagesize=20 order=updatetime}
<article>
<h2><a href="{$t.url}">{$t.title}</a></h2>
<p>{$t.description}</p>
</article>
{empty}
<p>暂无内容</p>
{/empty}
{/content}
<div class="pages">{$pages}</div>
子栏目:
{category module=article parent=$catid num=20 order=sort_asc,id_asc}
<a href="{$t.url}">{$t.name}</a>
{/category}
内容详情
<h1>{$title}</h1>
<div class="meta">
<span>发布时间:{$published_at}</span>
<span>浏览量:{$views}</span>
<span>栏目:{$category.name}</span>
</div>
{if $thumb}{thumb_img url=$thumb width=300 height=200 alt=$title}{/if}
<div class="content">{$content}</div>
字段展示区:
{loop $fields $name $field}
{if $field.text}
<div class="field field-{$name}">
<strong>{$field.label}</strong>
<span>{$field.text}</span>
</div>
{/if}
{/loop}
搜索
搜索表单:
<form action="/search" method="get" class="search-form">
<input type="hidden" name="module" value="article">
<input type="text" name="keyword" value="{$keyword}" placeholder="请输入关键词">
<button type="submit">搜索</button>
</form>
排序:
{sort_link value=new text="最新" class=sort-item}
{sort_link value=hits text="热门" class=sort-item}
{sort_link value=updatetime text="更新" class=sort-item}
搜索结果:
{search module=article keyword=$keyword page=1 pagesize=20 order=updatetime}
<a href="{$rs.url}">{$rs.title}</a>
{empty}
<p>暂无结果</p>
{/empty}
{/search}
<div class="pages">{$pages}</div>
图片和附件
图片类:
{thumb_url url=$thumb}
{thumb_img url=$thumb width=300 height=200 alt=$title}
{image_url url=$cover default="/assets/images/default.png"}
{image_img url=$cover width=300 height=200}
附件类:
{file_url url=$manual}
{file_link url=$manual text="下载文件"}
图片组:
{loop $gallery $image}
{image_img url=$image width=300 height=200}
{/loop}
多文件:
{loop $manuals $file}
{file_link url=$file}
{/loop}
自定义字段
详情页直接使用顶层变量:
{$cover}
{image_img url=$cover width=300 height=200}
列表循环里使用 $t:
{content model=article num=10}
{image_img url=$t.cover width=240 height=160}
{$t.fields.source.text}
{/content}
字段元信息:
fields.field_name.label
fields.field_name.value
fields.field_name.text
fields.field_name.type
启用 template_tag_generator 插件后,后台“标签生成器”会按“通用、首页、栏目/列表、内容、搜索、自定义字段”分组,可直接生成上述常用片段。