Forum Discussion

skylinegtr's avatar
10 years ago

Link and page access to Employee only

Is there a way to make the following link to be visible to employees only? See image below.

 

image1.png

 

I've created a custom page but I cannot make it accessible to employees only. Not sure what I'm doing wrong. Any help will be greatly appreciated.

  • skylinegtr - Here you go

     

    <ul>
    <li><a href="index.html">Knowledge & Support</a></li>
    <li><a href="index.html">Blogs</a></li>
    <li><a href="index.html">Forums</a></li>
    <li><a href="index.html">Idea Exchange</a></li>
    <li><a href="index.html">Events</a></li>
    <#if user.registered >
    <#assign show_module = false />
    <#list restadmin("/users/id/${user.id?c}/roles").roles.role as role>
    <#if role.name?? && (role.name == "Employee") || (role.name == "SECOND_ROLE")>
    <#assign show_module = true />
    </#if>
    </#list>
    <#if show_module>
    <li><a href="contact.html">Puritans</a></li>
    </#if>
    </#if>
    </ul>

     

    • skylinegtr's avatar
      skylinegtr
      Mentor

      I've tried to added in the if block but not working. I'm adding it to the wrong places. Can you please show me where exactly to add it? Sorry,  I'm not a programmar. 

      <#if user.registered > <#-- if the user is not anonymous -->
      <#assign show_module = false />
      <#list restadmin("/users/id/${user.id?c}/roles").roles.role as role> <#-- REST call to get the user's roles -->
      <#if role.name?? && (role.name == "Employee")>
      <#assign show_module = true />
      </#if>
      </#list>
      <#if show_module>
      <li><a href="contact.html">Puritans</a></li>
      </#if>

      • VarunGrazitti's avatar
        VarunGrazitti
        Boss

        skylinegtr - Here you go

         

        <ul>
        <li><a href="index.html">Knowledge & Support</a></li>
        <li><a href="index.html">Blogs</a></li>
        <li><a href="index.html">Forums</a></li>
        <li><a href="index.html">Idea Exchange</a></li>
        <li><a href="index.html">Events</a></li>
        <#if user.registered >
        <#assign show_module = false />
        <#list restadmin("/users/id/${user.id?c}/roles").roles.role as role>
        <#if role.name?? && (role.name == "Employee") || (role.name == "SECOND_ROLE")>
        <#assign show_module = true />
        </#if>
        </#list>
        <#if show_module>
        <li><a href="contact.html">Puritans</a></li>
        </#if>
        </#if>
        </ul>

         

    • skylinegtr's avatar
      skylinegtr
      Mentor

      VarunGrazitti - Awesome thank you! One more question. What if I want more than 1 role to access the link? Thank you in advance for all your help. 

  • skylinegtr - You need to see the roles in the user profile, if the user has the Employee role, show this link, else not. Try the following code. Replace the Employee_role in the code with the role name you have set for employees.

     

    <#if user.registered >  <#-- if the user is not anonymous -->
    	<#assign show_module = false />
    	<#list restadmin("/users/id/${user.id?c}/roles").roles.role as role>  <#-- REST call to get the user's roles -->
    		<#if role.name?? && (role.name == "EMPLOYEE_ROLE")>    
    			<#assign show_module = true />
    		</#if>
    	</#list>
    <#if show_module>
    	<!-- Show the items with access here -->
    </#if>

     

     

    I hope this helps.

    • skylinegtr's avatar
      skylinegtr
      Mentor

      VarunGrazitti - Thanks for the code. I've added the code but getting an " error message." I've checked line 170, column 6 and I don't see any problem. 

      Freemarker template 'ContentWrapper' parsing failed:

      ParseException:Parsing error in template "ContentWrapper" in line 170, column 6:
      Unclosed #if when the end of the file was reached.

       

      <ul>
      <li><a href="index.html">Knowledge & Support</a></li>
      <li><a href="index.html">Blogs</a></li>
      <li><a href="index.html">Forums</a></li>
      <li><a href="index.html">Idea Exchange</a></li>
      <li><a href="index.html">Events</a></li>
      <#if user.registered > <#-- if the user is not anonymous -->
      <#assign show_module = false />
      <#list restadmin("/users/id/${user.id?c}/roles").roles.role as role> <#-- REST call to get the user's roles -->
      <#if role.name?? && (role.name == "Employee")>
      <#assign show_module = true />
      </#if>
      </#list>
      <#if show_module>
      <li><a href="contact.html">Puritans</a></li>
      </#if>
      </ul>