On my site, there's teachers member group and students member group. I can protect nodes from students by allowing only teachers group with right-button context menu.
What I'd like to do, is to protect only a menu on a template. So, every one (logged in or not) could see the webpage, but only the loggedin teacher could see the top menu.
My menu is done by xslt, so I can verify if loggedIn, but how I verify if the member is in the right group? How I can tell this part of template or this macro that it's available only to teachers?
So one way to handle this would be to add this check to your XSLT macro anywhere it renders pages, for example:
<xsl:for-each select="$currentPage/* [@isDoc][string(umbracoNaviHide) != '1'][not(umbraco.library:IsProtected(@id, @path)) or umbraco.library:HasAccess(@id, @path)]">
(that would show pages that are not protected, or protected pages that the current user has access to)
Or if you know where you're rendering these pages (for example if the protected menu is it's own macro), you can simply wrap the if tag around your normal menu XSLT.
Ok, after some tests, I succeed. When I say menu, I want to say the html element, not only the link in it. So, in my xslt, I request the member group and, with an if, I display the element if the member has the right group.
Protect a menu only for certain groups only
Hi guys,
On my site, there's teachers member group and students member group. I can protect nodes from students by allowing only teachers group with right-button context menu.
What I'd like to do, is to protect only a menu on a template. So, every one (logged in or not) could see the webpage, but only the loggedin teacher could see the top menu.
My menu is done by xslt, so I can verify if loggedIn, but how I verify if the member is in the right group? How I can tell this part of template or this macro that it's available only to teachers?
Thank you for your help!
Hi,
You can use the HasAccess extension method to check if a the currently logged in user has access to a given page.
Ex:
<xsl:if test="umbraco.library:HasAccess(@id,@path) = true()">
So one way to handle this would be to add this check to your XSLT macro anywhere it renders pages, for example:
(that would show pages that are not protected, or protected pages that the current user has access to)
Or if you know where you're rendering these pages (for example if the protected menu is it's own macro), you can simply wrap the if tag around your normal menu XSLT.
HTH,
Tom
Ok, but how I can tell the menu that only a particular group hasaccess to it? I can only protect complete page? Not part of them?
The default implementation protects the whole page, and if you want to - hides it in the the menu.
Ok, after some tests, I succeed. When I say menu, I want to say the html element, not only the link in it. So, in my xslt, I request the member group and, with an if, I display the element if the member has the right group.
Thank for your help guys!
is working on a reply...