1.生成分页
本例使用文件是template/test2.html.生成列表分页的方法非常简单,只需要在标记中加上page属性,然后在你想显示分页页码导航的地方加上{$page}标记
下面是代码示例
<div align="center" style="margin-bottom:10px;">
{$t_news page="2"}{i} {n_title}<br />{/$}
</div>
{$page}
注意:page属性,order属性{$page}三者缺一不可,另外{i}属于特殊标记,代表循环当中的行号。
2.使用include标记
页面中公共的部分可以做成一个html,然后使用include标记引用
下面是代码示例
<div>
{$include src="head.html"}
</div>
3.循环嵌套的标记
首先声明一点,因为替换的原因,我推荐你在建表时,表与表的字段名称不要相同,否则在替换时会出现替换错误的情况
我们在写程序时经常碰到循环嵌套的情况,主要分为两种可能性:
第一种是两个不同表之间的嵌套,例如下面这样调取分类下的新闻
{$t_class_news order="order by n_class_id desc"}
{n_class_name}<br />
{$t_news where="n_class_id={n_class_id}"} {n_title}<br />{/$}
{/$}
第二种是同一个表之间的嵌套,本例亦可解决表和表之间字段名相同,防止替换错误的情况出现,例如父类调取子类
{$t_class_news where="n_parent_id=0" order="order by n_class_id desc" id="big"}
{big:n_class_name}<br />
{$t_class_news where="n_parent_id={big:n_class_id}" }{n_class_name}<br />{/$}
{/$}
4.if标记
如果在调取列表时需要第一行的样式与其他不相同,可以用if来判断,示例如下
{$t_news order="order by n_id desc"}
{$if({i}==1)}
<a href="a.html" style="color:red;">{n_id}</a>
{$else}
<a href="b.html">{n_id}</a>
{$endif}
{/$}
其中{$else}可以省略.
{$t_news order="order by n_id desc"}
{$if({i}==1)}
<a href="a.html" style="color:red;">{n_id}</a>
{$endif}
{/$}
5.字符串截取
字符串截取只需要这样
{n_title,20}
即可截取前20个字符。