Forum Discussion

simantel's avatar
9 years ago

Get Each Author's Role With Rest API

I'm attempted to create a custom component that will display each author's role beneath the stock Author component on the message page. Ideally, I'd add the information to the stock Author component,...
  • ChiaraS's avatar
    ChiaraS
    9 years ago

    Hi,

     

    ok in that case I think it would be ok, I would probably add a check on the name and only show the role if it's equal "Employee" or "Dealer", and not for other roles like "Administrator" or "Moderator".

     

    Back to your question, you could try the following approach:

     

    <#if env.context?? && env.context.message?? && env.context.message.author?? >
        <#assign author_id = env.context.message.author.id />
       
        <#attempt>
        <#list restadmin("/users/id/${author_id?c}/roles").roles.role as role>		
            <#if role.name == "Employee">
                ${role.name}
            </#if>
        </#list>
        <#recover>
        </#attempt>
    </#if>