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?
- AdamN14 years agoKhoros Oracle
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!
- DougS13 years agoKhoros Oracle
Hi Claudius,
Regarding your quesiton about freemarker in custom components: freemarker in custom content should be ok. If it wasn't rendering freemarker then you would probably see some of the freemarker code showing up as plan text or as invalid markup. If you are getting a "this widget cannot be displayed message" it is most likely because there is an exception when some of the freemarker runs. If you are logged in as someone who has full admin access, you should see the freemarker stack trace instead of the "widget cannot be displayed" message and this will help you debug the issue.
Related Content
- 11 years ago