我想知道是否有人可以给我一些关于如何创建Velocity模板以循环特定结构的Web Content项目的想法/片段,并根据特定结构字段的值呈现内容?
答案 0 :(得分:0)
以下是来自navigation.vm
的代码段,它将呈现群组链接:
#set($groupLocalService = $serviceLocator.findService("com.liferay.portal.service.GroupLocalService"))
#set($groupCount = $groupLocalService.getGroupsCount())
#set($groups = $groupLocalService.getGroups( 0, $groupCount))
<div id="community-links">
<ul>
#foreach ($group in $groups)
#if ($group.community && $group.name != 'Guest' && $group.hasPublicLayouts())
#set ($groupURL = $portletURLFactory.create($request, $group.name, $group.defaultPublicPlid, "ACTION_PHASE"))
${groupURL.setWindowState("normal")}
${groupURL.setPortletMode("view")}
${groupURL.setLifecycle("0")}
${groupURL.setParameter("groupId", ${group.getGroupId().toString()})}
${groupURL.setParameter("privateLayout", "false")}
#if ($group.getGroupId() == $themeDisplay.getLayout().getGroup().getGroupId() )
#set ($className = "selected")
#else
#set ($className = "unselected")
#end
<li class="${className}">
<a href="${groupURL.toString()}"><span>$group.getName()</span></a>
</li>
#end
#end
</ul>
</div>