Forum Discussion
HaidongG
13 years agoLithium Alumni (Retired)
Hi Riz,
There is nothing OOTB to set role to pages or components as I aware, but you may want to try something like this,
- create a macro via Studio->Endpoint->New Macro
<#function user_has_role role_name >
<#if user.registered>
<#list restadmin("/authentication/sessions/current/user/roles").roles.role as my_role>
<#if my_role.name?trim == role_name >
<#return true />
</#if>
</#list>
</#if>
<#return false />
</#function>
<#macro render_no_role >
You should contact XYZ by XYZ@ABC
</#macro>
- in your components, you can access them as long as you include the macro
<#include "your-macro-name.ftl" />
so, you may have some code like
<#assign expected_role = "company_vip" />
<#if user_has_role(expected_role) >
....acting normal....
<#else>
<@render_no_role />
</#if>