Skip to content

Instantly share code, notes, and snippets.

@farmerbradllc
Last active May 18, 2016 12:52
Show Gist options
  • Save farmerbradllc/2e2669d4dd4bee978d755e315a0094df to your computer and use it in GitHub Desktop.
Save farmerbradllc/2e2669d4dd4bee978d755e315a0094df to your computer and use it in GitHub Desktop.
Target User Segments for Navigation.vm
## -------- Audience Targeting Section -------- ##
#set ($userSegmentLocalService = $serviceLocator.findService("content-targeting-api","com.liferay.content.targeting.service.UserSegmentLocalService"))
#set ($assetCategoryLocalService = $serviceLocator.findService("com.liferay.portlet.asset.service.AssetCategoryLocalService"))
#set ($userSegmentIds = $request.getAttribute("userSegmentIds"))
## within the foreach loop of nav_items
## -------- START Audience Targeting Section -------- ##
#set ($hasUserSegment = false)
#set ($ignoreCategory = false)
#set ($navItemCategoryIds = $assetCategoryLocalService.getCategoryIds("com.liferay.portal.model.Layout", $nav_item.getLayout().getPlid()))
#foreach ($id in $userSegmentIds)
#set ($userSegmentId = $userSegmentLocalService.getUserSegment($id).getAssetCategoryId())
#foreach ($catId in $navItemCategoryIds)
#if ($userSegmentId == $catId)
#set($hasUserSegment = true)
#break
#else
#if ($userSegmentLocalService.fetchUserSegmentByAssetCategoryId($catId))
#set($hasUserSegment = false)
#break
#else
#set ($ignoreCategory = true)
#break
#end
#end
#end
#end
## -------- END Audience Targeting Section -------- ##
### wrap the navigation link with an #if ($navItemCategoryIds.size() == 0 || $hasUserSegment || $ignoreCategory))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment