Fórum

Access Website Custom Attribute in a Theme

Morad Ahmad, modificado 11 Anos atrás.

Access Website Custom Attribute in a Theme

Junior Member Postagens: 71 Data de Entrada: 16/06/10 Postagens Recentes
Hi,

I see the topic was investigated bevore. But I have the specific problem to get custom attrs values for a website.

I defined the custom attr "Type" for Websites to handle different sites according to their type.

Know I want to disply in the theme "portal_normal.vm" a menu with all sites of a specific type, say "city"

1. First Try:

...
#set ($groupLocalService = $serviceLocator.findService("com.liferay.portal.service.GroupLocalService"))
#set ($groupsCount = $groupLocalService.getGroupsCount())
#set ($allGroups = $groupLocalService.getGroups(0, $groupsCount))

#set ($gtyp = $group.getExpandoBridge().getAttribute("Type") )

...

2. Try:

...
#set ($gtyp = $group.getLayout().getExpandoBridge().getAttribute("Typ") )
...

3. Try

#set ($gtyp = $expandoValueLocalService.getData($group.getGroupId(),"com.liferay.portal.model.Website", "CUSTOM_FIELDS", "Typ", ... );


I also try to get webseites with webseiteLocalService

##set ($websiteService = $serviceLocator.findService("com.liferay.portal.service.WebsiteLocalService"))
##set ($sitesCount = $websiteService.getWebsitesCount())
##set ($allSites = $websiteService.getWebsites() )
##<h1> Anzahl = $sitesCount </h1>

But I didn't succed in all!:-). I am not a velocity programmer.

How to manage that?

Thanks,
Morad.
thumbnail
Thomas Berg, modificado 11 Anos atrás.

RE: Access Website Custom Attribute in a Theme

Regular Member Postagens: 131 Data de Entrada: 07/09/09 Postagens Recentes
Hello Morad,

I had the same requirement and got it working. I added a website attribute through the control-panel and I am able to access it in the theme like this:

#set ($site_shortname = $themeDisplay.getScopeGroup().getExpandoBridge().getAttribute("shortName"))


HTH

Thomas
Morad Ahmad, modificado 11 Anos atrás.

RE: Access Website Custom Attribute in a Theme

Junior Member Postagens: 71 Data de Entrada: 16/06/10 Postagens Recentes
Thanks Thomas,

but what I need is not the current group. I must read the attribute for each website in a foreach loop:


#foreach ($group IN $allGroups)
#if ($group.isSite())
#set ($type =....getAttribute("Type")) ## for group in iteration????
#if(!$group.isControlPanel())
#if($group.getGroupId() % 4 == 0)
#set ($myPlaceURL = $portletURLFactory.create($request, "49", $getterUtil.getLong($plid), "ACTION_PHASE"))
${myPlaceURL.setWindowState("normal")}
${myPlaceURL.setPortletMode("view")}
${myPlaceURL.setParameter("struts_action", "/my_sites/view")}
${myPlaceURL.setParameter("groupId", ${group.getGroupId().toString()})}
<li><a href="${myPlaceURL.toString()}">$group.getName()</a></li>
#end
#end
#end
#end


I am ver surprised why the WebsiteLocalService returns null/empty list when I try to get Websites in the portal? Is it a bug or I do it wrong??

Thanks,
Morad.