Combination View Flat View Tree View
Threads [ Previous | Next ]
Morad Ahmad
Access Website Custom Attribute in a Theme
August 26, 2012 8:58 AM
Answer

Morad Ahmad

Rank: Junior Member

Posts: 36

Join Date: June 16, 2010

Recent Posts

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.
Thomas Berg
RE: Access Website Custom Attribute in a Theme
September 6, 2012 1:33 AM
Answer

Thomas Berg

Rank: Regular Member

Posts: 125

Join Date: September 7, 2009

Recent Posts

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:

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


HTH

Thomas
Morad Ahmad
RE: Access Website Custom Attribute in a Theme
September 11, 2012 5:49 AM
Answer

Morad Ahmad

Rank: Junior Member

Posts: 36

Join Date: June 16, 2010

Recent Posts

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.