cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Highlighted
Honored Contributor

Banner or notification for specific roles

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

--
Community manager in the Micro Focus Community. My computer always used to beat me at chess, but it is no match for me now I changed the competition to kick boxing.
7 Replies 7
Highlighted
Honored Contributor

@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!

Highlighted
Honored Contributor

I'll give that a try. Thanks!


--
Community manager in the Micro Focus Community. My computer always used to beat me at chess, but it is no match for me now I changed the competition to kick boxing.
Highlighted
Khoros Alumni (Retired)

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.


Khoros Best Practice until August 2019. Onwards posting as Claudius.
Learn how to master Khoros. Learn Best Practice in the Community Documentation
If you appreciate my efforts, please give me a kudo ↓
Accept as solution to help others find it faster.
Highlighted

@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. 😞

--
Community manager in the Micro Focus Community. My computer always used to beat me at chess, but it is no match for me now I changed the competition to kick boxing.
Highlighted

@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 

--
Community manager in the Micro Focus Community. My computer always used to beat me at chess, but it is no match for me now I changed the competition to kick boxing.
Highlighted
Honored Contributor

@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!

--
Community manager in the Micro Focus Community. My computer always used to beat me at chess, but it is no match for me now I changed the competition to kick boxing.