问题
I was wondering if anyone could give me some ideas/snippets on how to create Velocity template to loop through Web Content items for a specific structure , and render the contents based on the value of a specific structure field?
回答1:
Here is a snippet from navigation.vm
that will render group links:
#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>
来源:https://stackoverflow.com/questions/8457663/how-to-find-web-contents-with-specific-structure-field-value