Forum Discussion
VarunGrazitti
Boss
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.
ChiaraS
9 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>
Related Content
- 4 years ago
- 5 years ago