Forum Discussion
VarunGrazitti
10 years agoBoss
yurikleban - Sure, try this.
<#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 == "Role1" || role.name == "Role2" || role.name == "Role3")>
<#assign user_has_role = true />
</#if>
</#list>
</#if>
<#if user_has_role >
Content will go here
</#if>
<#recover>
<!-- Something bad happened -->
</#attempt>
I hope this helps.
Sign in to react to this post
- ChiaraS10 years agoLithium Alumni (Retired)
You can also use REST v2 for that:
<#function user_has_role (id, roles)> <#assign liql = "SELECT id FROM users WHERE roles.name IN (${roles}) and id = '${id}'" /> <#assign query = rest("2.0","/search?q=" + liql?url) /> <#if (query.status == "success") && query.data.size gt 0> <#return true> <#else> <#return false> </#if> </#function>and call it like this:
<#if user.registered && user_has_role(user.id,"'Administrator', 'Lithium'")> ... </#if>
Sign in to react to this post- yurikleban10 years agoMentor
Thank you both for the info! Going to try it out for our personalized experience and will report back.
Cheers,
Yuri K.Sign in to react to this post