CmsTop模板制作幫助手冊(cè)(5)——模板語法

2010-09-09 21:06:26來源:作者:

1.      變量
示例:{$_username},顯示用戶名
2.      常量
示例:{IMG_URL},顯示公共js、css和圖片地址
3.      函數(shù)
示例:{str_cut($title,50)}, {url( 'system/seccode/image')}

1.      變量
示例:{$_username},顯示用戶名
2.      常量
示例:{IMG_URL},顯示公共js、css和圖片地址
3.      函數(shù)
示例:{str_cut($title,50)}, {url( 'system/seccode/image')}
函數(shù)對(duì)照表:
函數(shù)調(diào)用代碼示例
說明
{str_cut($title,50,'...')}
截?cái)嘧址?/div>
參數(shù)1:被截字符串
參數(shù)2:截?cái)嗪笞止?jié)數(shù)
參數(shù)3:被截?cái)嗪笞芳拥淖址ǹ蛇x)
{date('Y-m-d H:i',$published)}
日期格式化顯示
參數(shù)1:日期格式
參數(shù)2:unix時(shí)間戳
{thumb($r[thumb],90,90)}
自動(dòng)縮略圖
參數(shù)1:圖片地址
參數(shù)2:縮略圖寬度
參數(shù)3:縮略圖高度
{url( 'space/index/index','name=cmstop')}
構(gòu)造前臺(tái)動(dòng)態(tài)URL地址,可根據(jù)URL路由設(shè)置產(chǎn)生相應(yīng)格式的URL
參數(shù)1:app/controller/action
參數(shù)2:url參數(shù)(可選)
{article(1)->description}
顯示article表的主鍵值為1的description字段內(nèi)容,可以類似這樣調(diào)用任意數(shù)據(jù)表的字段
{table('category', 1, 'name')}
顯示欄目ID為1的欄目名稱
<?php $c = table('category', 1);?>
獲取欄目ID為1的欄目信息,一維數(shù)組
<?php $category = table('category');?>
獲取所有欄目信息,二維數(shù)組
{config('config','charset')}
調(diào)用./config/config.Php配置文件中的charset
{setting('comment','islogin')}
調(diào)用comment應(yīng)用的islogin設(shè)置
{pages($total,$page,20,2,'http://news.cmstop.net/2010/0317/943{$page}.shtml')}
分頁函數(shù)
{modelid('article')}
得到article的modelid
{username($userid)}
根據(jù)用戶ID得到用戶名
{userid($username)}
根據(jù)用戶名得到用戶ID
{loop channel() $cid $c}
<a href="{$c[url]}">{$c[name]}</a>
{/loop}
循環(huán)輸出頂級(jí)欄目信息
{loop subcategory($catid) $cid $c}
<a href="{$c[url]}">{$c[name]}</a>
{/loop}
循環(huán)輸出$catid的子欄目信息
{loop subdepartment(1) $did $d}
{$d[departmentid]},{$d[name]}
{/loop}
循環(huán)輸出部門ID為1的子部門信息
4.      邏輯判斷
示例:{if $c == 1} 顯示A {elseif $c == 2} 顯示B {else} 顯示C {/if}
5.      循環(huán)
示例:
{loop $array $k $v}
鍵:{$k} 值:{$v}
{/loop}
6.      模板嵌套
{template 'header.html'}
關(guān)鍵詞:CmsTop

贊助商鏈接: