Message Boards

Asset Renderer Get Asset Categories

Arun Pandian, modified 4 Years ago.

Asset Renderer Get Asset Categories

Junior Member Posts: 72 Join Date: 9/26/19 Recent Posts
Hi, Can i able to Get the Asset Category From Asset Publisher.. When i able set the Grouping to categories the asset Category is displaying but i want to print the asset category  in one of my asset publisher template is it possible?
thumbnail
Mohammed Yasin, modified 4 Years ago.

RE: Asset Renderer Get Asset Categories

Liferay Master Posts: 591 Join Date: 8/8/14 Recent Posts
Hi ,You can use Taglib for showing asset categories of selected asset entry in ftl
<@liferay_asset["asset-categories-summary"]
                    className=entry.getClassName()
                    classPK=entry.getClassPK()
                    portletURL=renderResponse.createRenderURL()
                />
Arun Pandian, modified 4 Years ago.

RE: Asset Renderer Get Asset Categories

Junior Member Posts: 72 Join Date: 9/26/19 Recent Posts
@Mohammed Yasin,

I want to print the asset category in template(ADT) your code does not help me

<#assign AssetCategoryLocalService = serviceLocator.findService("com.liferay.asset.kernel.service.AssetCategoryLocalService")>

<#assign values = portletPreferences['queryValues0'] />
<#if values?has_content>
<li>Query Values:
<ul>
<#list values as value>
<li>${value}</li>
<#assign assetCategory = AssetCategoryLocalService.getCategory(value?number) />${assetCategory.getTitle()}${assetCategory.getName()}<li>
</li>
</#list>
</ul>
</li>
</#if>

Hope it helps someone only issue is i am not able to get Name by locale as it takes 0 argument where as getTitle takes 1 argument locale but title is always empty when categories created from the control panel... can you help me on this?

thumbnail
Jan van der Kaaden, modified 4 Years ago.

RE: Asset Renderer Get Asset Categories

Junior Member Posts: 28 Join Date: 3/20/11 Recent Posts
Hi Mohamed,For as far as i know when you create a category (in the control-panel) you fill out the name, which underwater is the title, the default language will create the 'name' which has no translations. So what you probably want to use is the Title. If you need an extra field to put data in for a category you can also consider using the properties to add a key - value pair. Although this offers no localization,  maybe you can mimic that by a convention in the property name.