How do I get Sites of which the user is a member i

2020-08-01 01:46发布

问题:

In Liferay 6.1 custom theme - How can I get Sites for a user that it is a member of in a theme?

I have seen how the dockbar Go to/My sites gets generated via the Liferay UI taglib.

However, I want to get a list of user's sites and list them as part of super navigation bar separate from the dockbar options.

Is this possible and what is the API call to get the user's sites in a list?

Thanks in advance.

回答1:

From the user object you can retrieve the groups he belongs to:

$user.mySites

This returns a List<Group>. Once you have the Group you can easily build a URL to the public and private pages of this group:

<ul>
    #foreach($site in $user.mySites)
        #if ($site.hasPrivateLayouts())
            <li><a href="/group${site.friendlyURL}">$site.descriptiveName</a></li>
        #end
        #if ($site.hasPublicLayouts())
            <li><a href="/web${site.friendlyURL}">$site.descriptiveName</a></li>
        #end
    #end
</ul>