From time to time I want to put a notice or banner up on the home page and/or node pages that is only viewable by people with a certain role. For example I want to put a big notice, hard to miss, about some important community changes that is only viewable to company employees (have the employee role).
Is that possible and what's the best/easiest way to do that? Thanks - Kim
@kgroneman - If you want to display a banner for users who have ceartin roles, then you need to use the following code inside the custom component.
<#assign isEmployee = false />
<#list restadmin("/users/id/${user.id?c}/roles").roles.role as mainrole>
<#if mainrole.name?? && (mainrole.name == "Employee")>
<#assign isEmployee = true />
<#break>
</#if>
</#list>
<#if isEmployee>
..........................................YOUR BANNER CODE/COMPONENT.............................................
</#if>
Please let me know if this helps.
Thanks!
The Announcement feature accepts freemarker code in the content as well, so you don't even need to deploy a new custom content widget or similar, but can directly drop it via community admin in the announcement.
@ClaudiusH thanks, but I'm not a developer, and we don't have one on staff, so I have no clue how to use freemarker to do it. 😞
@kgroneman Try putting this code a custom content or the announcements box within a page: You would just need to update ROLEA, ROLEB, ROLEC to the roles you want to see this, and then add the appropriate text, image, code, to where i said so in the code below.
<#attempt>
<#assign user_has_role = false />
<#if user.registered >
<#list restadmin("/users/id/${user.id?c}/roles").roles.role as role>
<#if role.name?? && (role.name == "ROLEA" || role.name == "ROLEB" || role.name == "ROLEC")>
<#assign user_has_role = true />
</#if>
</#list>
</#if>
<#if user_has_role >
*THIS IS WHAT WILL DISPLAY IF THEY ARE IN THE ROLE*
<#else>
*THIS IS WHAT DISPLAYS IF THEY ARE NOT IN ONE OF THOSE ROLES*
</#if>
<#recover>
<!-- Something bad happened -->
</#attempt>
Thanks. I'm up to my eyeballs in other stuff right now but hope to get around to trying this out next week. I REALLY appreciate your input @StanGromer @ClaudiusH @Payal
@Payal @ClaudiusH @StanGromer I've finally found some time to play with this. Your suggestions work and it's simple. The ONLY problem I'm finding is that if the role doesn't match, the component (or announcement) still displays as blank (with no ELSE statement). Do you know of a way to make it as if the component is blank and doesn't display at all if the role criteria isn't met? Thank all 3 of you for your help!
Welcome to the Technology board!
Curious about our platform? Looking to connect on social technology? You've come to the right place!