I'm developing an application display template (freemarker) for the sitemap portlet to render in my layout in the pages footer. So far everything works. I can iterate through my pages and render the correct result. Checks on whether a page is hidden work as well.
Now I need one more feature. I want to check whether a page is accessible by logged users only (= don't show a link to a guest user when the page permissions forbid guests to see the page).
Here is my ADT code.
<#if entries?has_content>
<#list entries as entry>
<#assign layoutURL = portalUtil.getLayoutURL(entry, themeDisplay)>
<div class="grid3">
<ul>
<#if entry.isHidden() == false>
<li><a href="${layoutURL}">${entry.getName(locale)}</a></li>
</#if>
</ul>
</div>
</#list>
</#if>
Maybe ${themeDisplay.getPermissionChecker()}
can do the trick but I don't really have a clue on how to check for a users permissions on page. In a perfect world I can distinguish between different user groups but I'd settle for show when logged in, hide when anonymous (=guest).
I'm using Liferay 6.2. Anyone got an idea?
What you want to do is to check the view permission for a given page (Layout).
Freemarker snippet:
layoutPermission.contains(permissionChecker, entry.getPlid(), 'VIEW')
layoutPermission
is available for all ADT templates and references LayoutPermission
interface. entry
means the current Layout
instance.
I took the advice from this post on Liferay Forums.
To simply find out, if the user logged in you can call ThemeDisplay#isSignedIn
.
Freemarker snippet:
<#if themeDisplay.isSignedIn()>
<#-- user is logged in -->
<#else>
<#-- user is guest -->
</#if>