JEECMS 2.4.2 之添加新的可扩展的ftl模版文件、自定义方法
Demo:
<@cms.CfgList isPage='1' league='0' recommend='0' lala='0' hot='1' memberId='0' pageNo=pageNo count='4' orderBy=0 ;g> <dl> <dt><a href="/lala/LalaIndex.htm?fid=${g.id}" target="_blank"><img src="${g.logo}" /></a></dt> <dd> <span><a href="/lala/LalaIndex.htm?fid=${g.id}" target="_blank">${g.name!}</a></span> <#assign al=action.getArtiByCfgId(g.id!0).list> <#if al??> <#list al as ll> <#if ll.description?length gt 42> <a href="/lala/LaTopicDetail.htm?fid=${g.id}&aid=${ll.id}" target="_blank" style="text-decoration: none;">${ll.description?substring(0,41)}...</a> <#else> <a href="/lala/LaTopicDetail.htm?fid=${g.id}&aid=${ll.id}" target="_blank" style="text-decoration: none;">${ll.description!}</a> </#if> </#list> </#if> </dd> </dl> </@cms.CfgList>
上面的<@cms.CfgList...>之所以可以调用是因为在freemarker.properties:
auto_import="/WEB-INF/ftl_lib/ponyjava.com/index.ftl" as p, "/WEB-INF/ftl_lib/fcms/index.ftl" as cms
接下来顺藤摸瓜的跟进去看看index.ftl 找到相应的宏定义(macro)
<#-- 球迷会列表(自定义内容) team:所属俱乐部(默认为空) league:赛事(默认空) recommand:关联热门话题(默认0) orderBy:排序方式。【0:发布时间降序;1:发布时间升序;2:固顶降序;3:置顶降序;4:日点击降序;5:周点击降序;6:月点击降序;7:季点击降序;8:年点击降序;9:总点击降序】(默认0) memberId:关联版主。 hot:是否推荐 lala:0:啦啦团 1:球迷会 2:专题 --> <#macro CfgList league='0' recommend='0' orderBy='0' lala="-1" hot="0" memberId="0" count="5" pageNo="0" hot="0" titLen='20' target='0' headMark='0' lineHeight='' bottomLine='0' ctgForm='0' ctgClass='' dateFormat='0' datePosition='1' memberId="0" picWidth='24.9' picHeight='110' rollDisplayHeight='28' rollLineHeight='28' rightPadding='20' rollCols='1' rollSpeed='1' isSleep='1' rollSleepTime='50' rollCount='1' rollSpan='1' flashWidth='296' flashHeight='200' textHeight='20' isPage='0' count='20' firstResult='0' pageNo=pageNo style='1' inner='0' isLoop='1' cssClass='' cssStyle='' showLinkStyle='1' sysTpl='1' sysContent='0' userContent='' sysPage='0' newday='0' userPage='' upSolution='' upWebRes='' pageClass='' pageStyle='' custom=[]> <@s.action name='CfgList' league=league namespace='/fcms/tag/article' executeResult='true' memberId=memberId recommend=recommend orderBy=orderBy count=count lala=lala hot=hot titLen=titLen target=target headMark=headMark lineHeight=lineHeight bottomLine=bottomLine ctgForm=ctgForm ctgClass=ctgClass dateFormat=dateFormat datePosition=datePosition picWidth=picWidth picHeight=picHeight rollDisplayHeight=rollDisplayHeight rollLineHeight=rollLineHeight rightPadding=rightPadding rollCols=rollCols rollSpeed=rollSpeed isSleep=isSleep rollSleepTime=rollSleepTime rollCount=rollCount rollSpan=rollSpan flashWidth=flashWidth flashHeight=flashHeight textHeight=textHeight isPage=isPage count=count firstResult=firstResult pageNo=pageNo style=style cssClass=cssClass cssStyle=cssStyle showLinkStyle=showLinkStyle sysTpl=sysTpl sysContent=sysContent userContent=userContent sysPage=sysPage newday=newday userPage=userPage pageClass=pageClass pageStyle=pageStyle customs=customs /> <#if isLoop=='1'> <#list n_pagination.list as item> <#nested item,item_index,item_has_next/> </#list> <#else> <#nested n_pagination/> </#if> </#macro>
上述代码中不难发现使用了宏,并且会向指定的namespace、action参数请求数据,在这里提醒一下必须还要加上 <#nested> (指令执行指令开始和结束标记之间的模板片断)
否则在页面上打印出来的不是你想要的数据,而是你的项目src根目录下的各种文件名称,这一点我暂时没弄明白。
写博客不仅是一种习惯,更是一种沉淀。