Forum Discussion

frardouin's avatar
7 years ago

Render post differently if it's from an admin in a post listing (ex:add a class or more content)

I have a listing of posts and I want to check if the post author is an admin. I just want to add a css class and a image icon in that case. I'm still a little bit lost in the documentation. thanks you!

  • Hi,

    If you are using the rest api call to fetch the listing of posts, then you can first find the author id and check the role using following v1 api, based on that you will be able to add the icon or class.

     

    <#assign userRole = restadmin("/users/id/[authorID]/roles").roles.role />
    <#assign rolesArray = [] /> <#-- user can have multiple roles -->
    <#list userRole as role >
    <#assign rolesArray  = rolesArray + [role.name] />
    </#list>
    <#if rolesArray?seq_contains("Administrator")>
    //your code
    </#if>

    Let me know if this works for you.

     

    Thanks,

    Payal

  • Hi,

    If you are using the rest api call to fetch the listing of posts, then you can first find the author id and check the role using following v1 api, based on that you will be able to add the icon or class.

     

    <#assign userRole = restadmin("/users/id/[authorID]/roles").roles.role />
    <#assign rolesArray = [] /> <#-- user can have multiple roles -->
    <#list userRole as role >
    <#assign rolesArray  = rolesArray + [role.name] />
    </#list>
    <#if rolesArray?seq_contains("Administrator")>
    //your code
    </#if>

    Let me know if this works for you.

     

    Thanks,

    Payal