Forum Discussion

kentgilliam's avatar
11 years ago

Conditional based on rank

Can anyone tell me how I change this to render based on rank and not role? Is it as simple as changing "role" to "rank"? I'm doubting it is. 

 

<#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>

  • kentgilliam - It is indeed as simple as changing role to rank. The benifit in case of the rank vs roles is that a user could have multiple roles, so you would need to iterate through them, but the rank would always be one per user at a give time, it changes with the time and the metrics. So your code would be as below:

     

    <#assign user_has_rank = false />
    <#if user.registered >
    <#list restadmin("/users/id/[id]/ranking").ranking.name as rank>
    <#if rank?? && (rank == "Community Manager" || rank == "rank2" || rank == "rank3")>
    <#assign user_has_rank = true />
    </#if>
    </#list>
    </#if>
    <#if user_has_rank >
    Content will go here
    </#if>


     

  • kentgilliam - It is indeed as simple as changing role to rank. The benifit in case of the rank vs roles is that a user could have multiple roles, so you would need to iterate through them, but the rank would always be one per user at a give time, it changes with the time and the metrics. So your code would be as below:

     

    <#assign user_has_rank = false />
    <#if user.registered >
    <#list restadmin("/users/id/[id]/ranking").ranking.name as rank>
    <#if rank?? && (rank == "Community Manager" || rank == "rank2" || rank == "rank3")>
    <#assign user_has_rank = true />
    </#if>
    </#list>
    </#if>
    <#if user_has_rank >
    Content will go here
    </#if>


     

    • kentgilliam's avatar
      kentgilliam
      Mentor

      Thanks for the info. I thought it would be (hoped it would be) but I couldn't find any documentation. Thanks for confirming!

       

      Kent