models 欄目分類列表標簽
[基礎用法]
標簽:models
描述:易優常用標記,可以循環嵌套標簽。通常用于網站導航以獲取站點欄目信息。
用法:
{eyou:models type=’top’ loop=’8′ currentclass=’active’}
<li class=”{$field.currentclass}”><a href='{$field.typeurl}’? {$field.extends}>{$field.typename}</a> </li>
{/eyou:models}
屬性:
typeid=”欄目ID”
loop=’10’ 返回文檔列表總數(建議不要與limit屬性同時存在,否則loop無效)
limit=’起始ID,記錄數’ (起始ID從0開始)表示限定的記錄范圍(如:limit=’1,2′ 表示從ID為1的記錄開始,取2條記錄)
titlelen=’30’ 欄目名稱長度
type=’son’ 表示下級欄目
- type=’self’ 表示同級欄目
- type=’top’ 表示頂級欄目
- type=’sonself’ 表示當前下級欄目以及同級欄目
- type=’first’ 表示當前欄目ID的最頂級欄目下的第一級全部欄目
currentclass=” 應用樣式class類名
offset=’0′ 記錄的起始ID,默認從0開始,假如指定2,將過濾最前面的2條,從第三條顯示
name=” 數組類型的變量名(三級導航時才用到)
empty=” 沒有數據時顯示的文案
mod=” 每隔N行輸出的內容
id=” 可以任意指定循環里的變量名替代field,假設id=’field1’,模板調用如:{$field.title} 變成 {$field1.title}
涉及表字段:
請查閱易優cms官方提供的數據字典,找到表名 ey_arctype
(注:在沒有指定typeid的情況下,type標記與模板的環境有關,如:模板生成到欄目一,那么type=’son’就表示欄目一的所有子欄目)
注:{$field.extends}為新窗口打開/?等設置,直接放在a標簽的參數里即可
——————————-效果展示——————————–
1,調用頂級欄目導航
模板調用代碼
1,調用頂級欄目導航
模板調用代碼
{eyou:models type=”top” loop=”8″ id=”field” currentclass=”on”}
<li> <a class=”{$field.currentclass}” href=”{$field.typeurl}”>{$field.typename}</a> </li>
{/eyou:models}
網站前端顯示效果(css樣式請自行填充)
2.當前欄目下子欄目調用
模板調用代碼
{eyou:models loop=”6″ type =’son’ currentclass=”on”}
<li class=”{$field.currentclass}”><a href=”{$field.typeurl}” >{$field.typename}</a> </li>
{/eyou:models}
網站前端顯示效果(css樣式請自行填充)
【更多示例】
——————————-示例1——————————–
描述:輸出最頂級欄目,不包括子孫欄目,可用于網站簡單的頂部導航
{eyou:models type=”top” loop=”10″ currentclass=”active”}
<a href=”{$field.typeurl}” title=”{$field.typename}” class=”{$field.currentclass}”>{$field.typename}</a>
{/eyou:models}
——————————-示例2——————————–
描述:輸出二個層級欄目(這里用到models標簽層次嵌套,注意屬性id | name的用法)
{eyou:models type=’top’ loop=’10’ id=’field1′ currentclass=’active’} // 第一級欄目循環開始
<li>
<a href=”{$field1.typeurl}” title=”{$field1.typename}” class=”{$field1.currentclass}”>
{$field1.typename}
{eyou:notempty name=’$field1.children’} // 判斷是否有子欄目(該示例指的是第二級欄目)
有子欄目時才顯示這里的html代碼,比如:箭頭、圖標等
{/eyou:notempty}
</a>
{eyou:notempty name=’$field1.children’} // 判斷是否有子欄目(該示例指的是第二級欄目)
<div>
{eyou:models name=’$field1.children’ id=’field2′ loop=’10’} // 第二級欄目循環開始
<a href=”{$field2.typeurl}” class=”dropdown-item “>{$field2.typename}</a>
{/eyou:models} // 第二級欄目循環結束
</div>
{/eyou:notempty}
</li>
{/eyou:models} // 第一級欄目循環結束
——————————-示例3——————————–
描述:輸出復雜的三個層級欄目(這里用到models標簽層次嵌套,注意屬性id | name的用法)
{eyou:models type=’top’ loop=’10’ id=’field1′ currentclass=’active’} // 第一級欄目循環開始
<li>
<a href=”{$field1.typeurl}” title=”{$field1.typename}” class=”{$field1.currentclass}”>
{$field1.typename}
{eyou:notempty name=’$field1.children’}
有子欄目時才顯示這里的html代碼,比如:箭頭、圖標等
{/eyou:notempty}
</a>
{eyou:notempty name=’$field1.children’} // 判斷是否有子欄目(第二級欄目)start
<div>
{eyou:models name=’$field1.children’ id=’field2′ loop=’10’} //第二級欄目循環開始
<div>
<a href=”{$field2.typeurl}” class=”dropdown-item “>{$field2.typename}</a>
{eyou:notempty name=’$field2.children’} // 判斷是否有子欄目(第三級欄目)start
<div class=”dropdown-menu animate”>
{eyou:models name=’$field2.children’ id=’field3′ loop=’10’} //第三級欄目循環開始
<a href=”{$field3.typeurl}” class=”dropdown-item “>{$field3.typename}</a>
{/eyou:models} //第三級欄目循環結束
</div>
{/eyou:notempty} // 判斷是否有子欄目(第三級欄目)end
</div>
{/eyou:models} // 第二級欄目循環結束
</div>
{/eyou:notempty} // 判斷是否有子欄目(第二級欄目)end
</li>
{/eyou:models} //第一級欄目循環結束
——————————-示例4——————————–
描述:每隔3條輸出文檔記錄
{eyou:models typeid=’文檔ID’ loop=’10’ mod=’3′}
{eyou:eq name=’mod’ value=’0′}
<a href='{$field.typeurl}’>{$field.typename}</a>
{/eyou:eq}
{/eyou:models}
——————————-示例5——————————–
描述:mod屬性還用于控制一定記錄的換行,每3條記錄換行一次
{eyou:models typeid=’文檔ID’ loop=’10’ mod=’3′}
<a href='{$field.typeurl}’>{$field.typename}</a>
{eyou:eq name=’mod’ value=’0′}
<br/>
{/eyou:eq}
{/eyou:models}
——————————-示例6——————————–
描述:輸出指定起始ID的記錄,過濾最前面2條,從第三條開始輸出
{eyou:models typeid=’欄目ID’ type=’son’ offset=’2′}
<a href='{$field.typeurl}’>{$field.typename}</a>
{/eyou:models}
——————————-示例7——————————–
描述:內置變量輸出數據索引與記錄順序,key 表示索引,默認從0開始;i 表示順序,默認從1開始。
{eyou:models type=’top’}
{$key} – {$i}
{/eyou:models}
效果:
0 – 1
1 – 2
2 – 3
3 – 4
4 – 5
——————————-示例8——————————–
描述:自定義變量名
{eyou:models type=’top’ id=’field2′}
<a href='{$field2.typeurl}’>{$field2.typename}</a>
{/eyou:models}
聲明:本站所有文章,如無特殊說明或標注,均為本站原創發布。任何個人或組織,在未征得本站同意時,禁止復制、盜用、采集、發布本站內容到任何網站、書籍等各類媒體平臺。如若本站內容侵犯了原著者的合法權益,可聯系我們進行處理。