Foren

Hide a portlet and its boundarybased on a users role

bob brinks, geändert vor 10 Jahren.

Hide a portlet and its boundarybased on a users role

New Member Beiträge: 10 Beitrittsdatum: 20.06.13 Neueste Beiträge
My suggestion:
[indent]I know i can hide a portlet using roles + permissions and layout.show.portlet.access.denied=false.

But what i'd like to see is an option to also hide the html taking the place of the 'hidden' portlet:

<div class="portlet-boundary portlet-boundary_portletName_WAR_portletName_  portlet-static portlet-static-end portlet-borderless document-publisher-portlet col-md-12 col-lg-12 col-sm-12" id="p_p_id_portletName_WAR_portletName_INSTANCE_Y096lxZEugka_">
        <span id="p_portletName_WAR_portletName_INSTANCE_Y096lxZEugka"></span>
        <div class="portlet-body">
        </div>
</div>


Or possibly add a css class so I can identify this portlet is not visible for the current user.
[/indent]

Then my question as well:

[indent]
Is there anyone who has done this with a hook or something like that in CE 6.1.2 version of liferay or the CE 6.2.0. And could you share the way you did it?
I'm currently using jQuery to fix this problem but it's causing some problems with the bootstrap 3 theme I made. It causes a lot of 'jumpiness' on the client after load.
[/indent]
thumbnail
Victor Zorin, geändert vor 10 Jahren.

RE: Hide a portlet and its boundarybased on a users role

Liferay Legend Beiträge: 1228 Beitrittsdatum: 14.04.08 Neueste Beiträge
If your theme uses for example jQuery you can invoke on page loading:
- find the element .portlet-boundary > .portlet-body
- check if it has empty content
- if yes, apply display: none to its direct parent, which is .portlet-boundary

Otherwise you would have to dig through jsps that handle portlets rendering and find the point where you would have to reverse the order of permissions and portlet rendering, which may be tricky or not possible due to sequencing.
bob brinks, geändert vor 10 Jahren.

RE: Hide a portlet and its boundarybased on a users role

New Member Beiträge: 10 Beitrittsdatum: 20.06.13 Neueste Beiträge
Thanks for your reply. jQuery was my current solution aswell but it's not a very 'nice' way to do this so I'm looking for something serverside.

I've updated the OP to specify this.
thumbnail
Victor Zorin, geändert vor 10 Jahren.

RE: Hide a portlet and its boundarybased on a users role (Antwort)

Liferay Legend Beiträge: 1228 Beitrittsdatum: 14.04.08 Neueste Beiträge
Yes, it would be jumpy, so had a quick look at jsps...

Try to investigate html/portal/render_portlet.jsp. Find lines:

cssClasses = "portlet-boundary ..." and
<div class="portlet-body">

below these lines you will see:
<c:when test="<%= !access && !portlet.isShowPortletAccessDenied() %>">
</c:when>

It looks like everything is available in one place and therefore it is feasible to add "display:none" or your own css class "hide" into cssClasses scriplet and/or next to "portlet-body" word.

Once it is working, make a standard jsp hook.
bob brinks, geändert vor 10 Jahren.

RE: Hide a portlet and its boundarybased on a users role

New Member Beiträge: 10 Beitrittsdatum: 20.06.13 Neueste Beiträge
Thanks for looking into it, this will work great for my solution.