Forum Discussion
I tried to adapt this example to display different custom content based on different roles but I can't get hold of the current user's roles.
And as a bonus question: When I try to use this freemarker code in Custom Content it shows a "This widget could not be displayed." message instead. Is Freemarker code not allowed within Custom Content?
Hi Claudius,
A couple of notes...
First, I'd suggest double checking to ensure that you're using the correct REST API method. To get the user's roles, the call should look like:
/users/id/${user.id?c}/roles
Second, a user can have only one rank at a time, whereas they can have multiple roles. So the approach for determining whether a user has a particular role is a bit different than just seeing what their rank is. Here's an example I posted previously of showing specific content to only Administrators or Moderators:
<#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 == "Administrator" || role.name == "Moderator")> <#assign user_has_role = true /> </#if> </#list> </#if> <#if user_has_role > Show to users with role </#if>
It may be easier to adapt the example above. I hope this helps!
Related Content
- 11 years ago