Mani
Mani

Reputation: 293

Programatically filter web content by scope in Liferay 6.2.GA2

Updating to have more info: Is there any way to programatically select all the web content from global scope or currently selected site scope.

I want to do this in velocity template "portal_normal.vm". I wrote "$themeDisplay.getScopeGroupId().toString()" to get group id.

I have 2 sites/communities and I have assigned one user to each of them. One site is default liferay site which has default liferay user.Other site is my custom site and has my own user. When I try to login with each of them ,I always get group id of liferay site.Is there any other method I need to use to get site of current logged in user?

Upvotes: 0

Views: 1175

Answers (1)

rp.
rp.

Reputation: 3465

You must allow the usage of ServiceLocator in your Velocity templates. In your portal-ext.properties set the following:

journal.template.velocity.restricted.variables=

If you already have these keys set, just remove serviceLocator from the list.

Using serviceLocator we can load GroupLocalServiceUtil and JournalArticleLocalServiceUtil. Its very simple to obtain all the sites WebContent:

#set ($journal_article_local_service = $serviceLocator.findService("com.liferay.portal.service.JournalArticleLocalService"))

#set ($journal_articles = $journal_article_local_service.getArticles($theme_display.getScopeGroupId()))

To get all the ones in the global scope:

For the global group:

#set ($group_local_service = $serviceLocator.findService("com.liferay.portal.service.GroupLocalService"))

#set ($global_group = $group_local_service.getGroup($theme_display.getCompanyId(), "Global"))

#set ($journal_article_local_service = $serviceLocator.findService("com.liferay.portal.service.JournalArticleLocalService"))

#set ($journal_articles = $journal_article_local_service.getArticles($global_group.getGroupId()))

Upvotes: 2

Related Questions