注意事项

  1. 模板文件后缀:无、.htm、.html
  2. 被引入的文件格式必须为 .vm

静态资源目录

1
$pathUtil.getSiteUrl($site)/

导入公共文件

1
#parse("header.vm")

TDK 相关

1
2
3
首页:$site.fullName
索引页:${curChannel.title}-$site.fullName
文章页:${curArticle.name}-${curChannel.title}-$site.fullName

单个调用

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
首页:$rootChannel.title
首页链接:$cms.getUrl($rootChannel)
栏目名:$cms.getChannelByName('工作动态').title
栏目链接:$cms.getUrl('工作动态')
栏目图:$cms.getChannelLogoUrl($channel)
时间格式化:$cms.format($article.publishDate,"yyyy-MM-dd hh:mm")
当前栏目名称:$curChannel.name
当前栏目链接:$cms.getUrl($curChannel)
当前栏目父栏目名称:$cms.getChannel($curChannel.parentID).title
通过名字获取栏目:
$cms.getChannel('栏目')
$cms.getChannelByName('栏目名')

判断摘要,为空则取内容的前30个字符 (单独使用 $stringUtil.summary($article.summary,30) 报错时采用下面写法)
#if($stringUtil.nullFilter($article.summary)!="")
$stringUtil.summary($article.summary,30)
#else
#set($fullArticle=$cmsService.getArticle($article.id))
$stringUtil.summary($cms.clearHtml($fullArticle.content),30)
#end

搜索

1
2
3
4
5
<form class="search_form" action="/cms/web/search/index.jsp">
<input name="query" type="text" value="输入关键字">
<input type="submit" name="FindButton" value=" ">
<input type=hidden name=siteID value="$site.id" />
</form>

循环导航栏目

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<div class="nav-box">
<div class="nav-box_item #if($rootChannel.title==$curChannel.title) on #end"><a href="$cms.getUrl($rootChannel)">$rootChannel.title</a></div>
#foreach($channel in $cms.getTopChildren($rootChannel))
<div class="nav-box_item #if($channel.title==$curChannel.title) on #end">
<a href="$cms.getUrl($channel)">$channel.title</a>
#if($cms.getChannelCount($channel.id) > 0)
<span class="nav-box_item-arrow"><i class="iconfont icon-arrow-right"></i></span>
<div class="sub-box">
#foreach($subChannel in $cms.getChildren($channel))
<div class="sub-box_item"><a href="$cms.getUrl($subChannel)">$subChannel.title</a></div>
#end
</div>
#end
</div>
#end
</div>

循环某个具体栏目下的子栏目

1
2
3
4
5
#foreach($channel in $cms.getChildrenByName("实验中心"))
链接:$cms.getUrl($channel)
标题: $channel.title
图片:$cms.getChannelLogoUrl($channel)
#end

循环当前栏目的子栏目

1
2
3
4
5
#foreach($channel in $cms.getChildren($cms.getChannel($curChannel.id)))
链接:$cms.getUrl($channel)
标题: $channel.title
图片:$cms.getChannelLogoUrl($channel)
#end

循环当前栏目的父栏目下的子栏目

1
2
3
4
5
#foreach($channel in $cms.getChildren($cms.getChannel($curChannel.parentID)))
链接:$cms.getUrl($channel)
标题: $channel.title
图片:$cms.getChannelLogoUrl($channel)
#end

首页-循环某个具体栏目列表

1
2
3
4
5
6
7
8
9
10
11
12
13
// 参数解释:栏目名称,从第几个开始,取几个
#foreach($article in $cms.getContentsByChannelName("学院动态",1,1))
图片: $cms.getPictureUrl($article)
文章中拿指定的位置的相关图片: $cms.getUrl($cms.getPicture($curArticle,n))
相关图片列表:$cms.getPictures($article)
链接:$cms.getUrl($article)
标题:$article.name
时间:$article.publishDate
时间格式化:$cms.format($article.publishDate,"yyyy-MM-dd hh:mm")
摘要:$article.summary
当摘要不为空时展示: $!{article.summary}
获取循环索引:${foreach.index}
#end

面包屑

1
2
3
4
5
6
7
8
9
<div class="bread">
<span>当前位置:
# 当前页面的id getPathChannels 取得当前栏目到根栏目的集合
#foreach($tmpChannel in $cms.getPathChannels($curChannel.id))
<a href="$cms.getUrl($tmpChannel)">$tmpChannel.title</a>&raquo;
#end
<a href="$cms.getUrl($curChannel)">$curChannel.title</a>&raquo;
</span>
</div>

列表页循环当前栏目下的文章列表

1
2
3
#foreach($article in $cms.getContents($curChannel,10))
$stringUtil.summary($article.name,40)
#end

分页

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
效果:首页 上一页  下一页 尾页 转到x页
<form name=pageForm action="" method=post>
共$totalRows条,分$totalPage页,当前第$curPage页

#if($curPage>1)
<a href="$cms.getIndexFileName($curChannel,1)" >首页</a>
<a href="$cms.getIndexFileName($curChannel,$prePage)">上一页</a>
#else
<a>首页</a>
<a>上一页</a>
#end

#if($curPage>5)
<a>...</a>
#end

#foreach($index in [$left..$right])
#if ($index == $curPage)
<a href="$cms.getIndexFileName($curChannel, $index)" class="on_page">$index</a>
#else
<a href="$cms.getIndexFileName($curChannel, $index)">$index</a>
#end
#end

#if($nextPage<$totalPage+1)
<a href="$cms.getIndexFileName($curChannel,$nextPage)">下一页</a>
<a href="$cms.getIndexFileName($curChannel,$totalPage)">尾页</a>
#else
<a>下一页</a>
<a>尾页</a>
#end

转到第
<select style="width:43px; heihgt:18px; line-height:18px;" name="page" onchange="javascript:PageFormSubmit()">
#foreach($currPage in [1..$totalPage])
#set ($selected = '')
#if($currPage == $curPage)
#set ($selected = 'selected')
#end
<option value="$cms.getIndexFileName($curChannel, $currPage)" $selected>$currPage</option>
#end
</select>

</form>
<script>
function PageFormSubmit() {
document.location.href=document.pageForm.page.options[document.pageForm.page.selectedIndex].value;
}
</script>

索引文章页(概况形式)

1
2
3
4
5
#foreach($article in $cms.getContents($curChannel,0,1))
#set($fullArticle=$cmsService.getArticle($article.id))
标题:$fullArticle.name
内容:$!{fullArticle.content}
#end

单个文章属性表

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
标题: $curArticle.name
副标题: $!{curArticle.viceTitle}
内容: $curArticle.content
简介页中有pdf文件的: $!{cms.getArticleContent($fullArticle)}
摘要: $!{curArticle.summary}
供稿: $!{curArticle.supplyArticle}
关键字: $!{curArticle.keyword}
来源: $!{curArticle.source}
作者: $!{curArticle.author}
审核人: $curArticle.auditUserName
级别: $!{curArticle.grade}
发布日期: $cms.format($curArticle.publishDate,"yyyy-MM-dd HH:mm:ss")
价格: $!{curArticle.price}
(除开以上部分) 扩展属性:$!{curArticle.getProperty("fangxiagn")}
注:扩展属性中字段填写在内容类型中定义的字段名

标题相关
1、获取标题:$curArticle.title
2、获取标题(包含全部样式):$cms.getContentTitleStyle($curArticle.id)
3、获取标题颜色:$cms.getSrcContent($curArticle.id).titleColor

获取访问量

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<!-- 文章访问量: -->
<script src="/cms/web/writeLog.jsp?siteID=$curChannel.siteID&channelID=$curChannel.id&contentID=$curArticle.id"></script>
<div style="display:none;"><script src="/cms/web/writeLog.jsp?siteID=$curChannel.siteID&channelID=$curChannel.id&contentID=$curArticle.id"></script></div>

<!-- 栏目访问量,把contentID设置成0 -->
<div style="display:none;"><script src="/cms/web/writeLog.jsp?siteID=$curChannel.siteID&channelID=$curChannel.id&contentID=0"></script></div>

<!-- 站点访问量,contentID和channelID都设置成0 -->
<script src="/cms/web/writeLog.jsp?siteID=$curChannel.siteID&channelID=0&contentID=0"></script>

<span class="view gp-hide">访问量:<strong id="gpViewCount"><script async src="/cms/web/writeLog.jsp?siteID=$curChannel.siteID&channelID=$curChannel.id&contentID=$curArticle.id"></script></strong></span>

<script src="/cms/web/writeLog.jsp?siteID=$curChannel.siteID&channelID=$curChannel.id&contentID=$curArticle.id"></script>
<div style="display:none;"><script src="/cms/web/writeLog.jsp?siteID=$curChannel.siteID&channelID=$curChannel.id&contentID=$curArticle.id"></script></div>

三级侧边栏

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
//判断当前栏目父栏目是不是首页(根栏目)
#if($cms.getChannel($curChannel.parentID).root)
#set($getName=$curChannel)
// 父级的父级=首页
#elseif($cms.getChannel($cms.getChannel($curChannel.parentID).parentID).root)
#set($getName=$cms.getChannel($curChannel.parentID))
#else
#set($getName=$cms.getChannel($cms.getChannel($curChannel.parentID).parentID))
#end

<ul>
#foreach($channel1 in $cms.getChildren($getName))
#if($cms.getChannelCount($channel1.ID) > 0)
<li>
<a href="$cms.getUrl($channel1)">$channel1.title</a>
<ul>
#foreach($channel2 in $cms.getChildren($channel1))
<li class="#if($channel2.name ==$curChannel.name) on #end"><a href="$cms.getUrl($channel2)">$channel2.title</a></li>
#end
</ul>
</li>
#else
<li class="#if($channel1.name == $curChannel.name) on #end"><a href="$cms.getUrl($channel1)">$channel1.title</a></li>
#end
#end
</ul>

封面页循环当前栏目下子栏目以及子栏目下列表

1
2
3
4
5
6
7
8
9
10
11
#foreach($channel in $cms.getChildren($cms.getChannel($curChannel.id)))
// 循环子栏目
<a href="$cms.getUrl($channel)">$channel.title</a>

// 循环子栏目下的文章列表
#foreach($article in $cms.getContents($channel,7))
链接:$cms.getUrl($article)
标题:$article.name
#end

#end