[基礎(chǔ)用法]
名稱:channel
功能:易優(yōu)常用標(biāo)記,可以循環(huán)嵌套標(biāo)簽。通常用于網(wǎng)站導(dǎo)航以獲取站點(diǎn)欄目信息,方便網(wǎng)站會(huì)員分類瀏覽整站信息
語法:
{eyou:channel type='top' row='8' currentstyle='active'}
<li class="{$field.currentstyle}"><a href='{$field.typeurl}'>{$field.typename}</a> </li>
{/eyou:channel}
參數(shù):
typeid='' 欄目ID,多個(gè)請(qǐng)用","分開
row='10' 返回文檔列表總數(shù)(建議不要與limit屬性同時(shí)存在,否則row無效)
limit='起始ID,記錄數(shù)' (起始ID從0開始)表示限定的記錄范圍(如:limit='1,2' 表示從ID為1的記錄開始,取2條記錄)
titlelen='30' 欄目名稱長度
type='son' 表示下級(jí)欄目
- type='self' 表示同級(jí)欄目
- type='top' 表示頂級(jí)欄目
- type='sonself' 表示當(dāng)前下級(jí)欄目以及同級(jí)欄目
- type='first' 表示當(dāng)前欄目ID的最頂級(jí)欄目下的所有層級(jí)欄目集合
currentstyle='' 應(yīng)用樣式class類名
offset=‘0’ 記錄的起始ID,默認(rèn)從0開始,假如指定2,將過濾最前面的2條,從第三條顯示
name='' 數(shù)組類型的變量名(三級(jí)導(dǎo)航時(shí)才用到)
empty='' 沒有數(shù)據(jù)時(shí)顯示的文案
mod='' 每隔N行輸出的內(nèi)容
id='' 可以任意指定循環(huán)里的變量名替代field,假設(shè)id='field1',模板調(diào)用如:{$field.title} 變成 {$field1.title}
底層字段:
請(qǐng)查閱易優(yōu)Cms官方提供的數(shù)據(jù)字典,找到表名 ey_arctype
(注:在沒有指定typeid的情況下,type標(biāo)記與模板的環(huán)境有關(guān),如:模板生成到欄目一,那么type='son'就表示欄目一的所有子欄目)
-------------------------------效果展示--------------------------------1,調(diào)用頂級(jí)欄目導(dǎo)航
模板調(diào)用代碼
{eyou:channel type="top" row="8" id="field" currentstyle="on"}
<li> <a class="{$field.currentstyle}" href="{$field.typeurl}">{$field.typename}</a> </li>
{/eyou:channel}
網(wǎng)站前端顯示效果(css樣式請(qǐng)自行填充)
2.當(dāng)前欄目下子欄目調(diào)用
模板調(diào)用代碼
{eyou:channel row="6" type ='son' currentstyle="on"}
<li class="{$field.currentstyle}"><a href="{$field.typeurl}" >{$field.typename}</a> </li>
{/eyou:channel}
網(wǎng)站前端顯示效果(css樣式請(qǐng)自行填充)
【更多示例】
-------------------------------示例1--------------------------------
描述:輸出最頂級(jí)欄目,不包括子孫欄目,可用于網(wǎng)站簡單的頂部導(dǎo)航
{eyou:channel type="top" row="10" currentstyle="active"}
<a href="{$field.typeurl}" title="{$field.typename}" class="{$field.currentstyle}">{$field.typename}</a>
{/eyou:channel}
-------------------------------示例2--------------------------------
描述:輸出二個(gè)層級(jí)欄目(這里用到channel標(biāo)簽層次嵌套,注意屬性id | name的用法)
{eyou:channel type='top' row='10' id='field1' currentstyle='active'} // 第一級(jí)欄目循環(huán)開始
<li>
<a href="{$field1.typeurl}" title="{$field1.typename}" class="{$field1.currentstyle}">
{$field1.typename}
{eyou:notempty name='$field1.children'} // 判斷是否有子欄目(該示例指的是第二級(jí)欄目)
有子欄目時(shí)才顯示這里的html代碼,比如:箭頭、圖標(biāo)等
{/eyou:notempty}
</a>
{eyou:notempty name='$field1.children'} // 判斷是否有子欄目(該示例指的是第二級(jí)欄目)
<div>
{eyou:channel name='$field1.children' id='field2' row='10'} // 第二級(jí)欄目循環(huán)開始
<a href="{$field2.typeurl}" class="dropdown-item ">{$field2.typename}</a>
{/eyou:channel} // 第二級(jí)欄目循環(huán)結(jié)束
</div>
{/eyou:notempty}
</li>
{/eyou:channel} // 第一級(jí)欄目循環(huán)結(jié)束
-------------------------------示例3--------------------------------
描述:輸出復(fù)雜的三個(gè)層級(jí)欄目(這里用到channel標(biāo)簽層次嵌套,注意屬性id | name的用法)
{eyou:channel type='top' row='10' id='field1' currentstyle='active'} // 第一級(jí)欄目循環(huán)開始
<li>
<a href="{$field1.typeurl}" title="{$field1.typename}" class="{$field1.currentstyle}">
{$field1.typename}
{eyou:notempty name='$field1.children'}
有子欄目時(shí)才顯示這里的html代碼,比如:箭頭、圖標(biāo)等
{/eyou:notempty}
</a>
{eyou:notempty name='$field1.children'} // 判斷是否有子欄目(第二級(jí)欄目)start
<div>
{eyou:channel name='$field1.children' id='field2' row='10'} //第二級(jí)欄目循環(huán)開始
<div>
<a href="{$field2.typeurl}" class="dropdown-item ">{$field2.typename}</a>
{eyou:notempty name='$field2.children'} // 判斷是否有子欄目(第三級(jí)欄目)start
<div class="dropdown-menu animate">
{eyou:channel name='$field2.children' id='field3' row='10'} //第三級(jí)欄目循環(huán)開始
<a href="{$field3.typeurl}" class="dropdown-item ">{$field3.typename}</a>
{/eyou:channel} //第三級(jí)欄目循環(huán)結(jié)束
</div>
{/eyou:notempty} // 判斷是否有子欄目(第三級(jí)欄目)end
</div>
{/eyou:channel} // 第二級(jí)欄目循環(huán)結(jié)束
</div>
{/eyou:notempty} // 判斷是否有子欄目(第二級(jí)欄目)end
</li>
{/eyou:channel} //第一級(jí)欄目循環(huán)結(jié)束
-------------------------------示例4--------------------------------
描述:每隔3條輸出文檔記錄
{eyou:channel typeid='文檔ID' row='10' mod='3'}
{eyou:eq name='mod' value='0'}
<a href='{$field.typeurl}'>{$field.typename}</a>
{/eyou:eq}
{/eyou:channel}
-------------------------------示例5--------------------------------
描述:mod屬性還用于控制一定記錄的換行,每3條記錄換行一次
{eyou:channel typeid='文檔ID' row='10' mod='3'}
<a href='{$field.typeurl}'>{$field.typename}</a>
{eyou:eq name='mod' value='0'}
<br/>
{/eyou:eq}
{/eyou:channel}
-------------------------------示例6--------------------------------
描述:輸出指定起始ID的記錄,過濾最前面2條,從第三條開始輸出
{eyou:channel typeid='欄目ID' type='son' offset='2'}
<a href='{$field.typeurl}'>{$field.typename}</a>
{/eyou:channel}
-------------------------------示例7--------------------------------
描述:內(nèi)置變量輸出數(shù)據(jù)索引與記錄順序,key 表示索引,默認(rèn)從0開始;i 表示順序,默認(rèn)從1開始。
{eyou:channel type='top'}
{$key} - {$i}
{/eyou:channel}
效果:
0 - 1
1 - 2
2 - 3
3 - 4
4 - 5
-------------------------------示例8--------------------------------
描述:自定義變量名
{eyou:channel type='top' id='field2'}
<a href='{$field2.typeurl}'>{$field2.typename}</a>
{/eyou:channel}
本頁內(nèi)容由塔燈網(wǎng)絡(luò)科技有限公司通過網(wǎng)絡(luò)收集編輯所得,所有資料僅供用戶參考了本站不擁有所有權(quán),如您認(rèn)為本網(wǎng)頁中由涉嫌抄襲的內(nèi)容,請(qǐng)及時(shí)與我們聯(lián)系,并提供相關(guān)證據(jù),工作人員會(huì)在5工作日內(nèi)聯(lián)系您,一經(jīng)查實(shí),本站立刻刪除侵權(quán)內(nèi)容。本文鏈接:http://m.jstctz.cn/10936.html