Forum Discussion

PerBonomi's avatar
10 years ago

Change Page based on user

Hi there. I created a custom Community Page and I'd like to enable it only for select users. Is this possible?

 

I saw that page initialization will let me change the quilt, but I need more :)

  • Even simpler then, add the redirection to the custom page in the page initialization code i shared earlier.
  • Even simpler then, add the redirection to the custom page in the page initialization code i shared earlier.
      • PerBonomi's avatar
        PerBonomi
        Boss

        Hey. So, it turns out the code does work; there's just some glitch with our Staging environment.

         

        So, in case someone wants to try, you can replace any page on the fly:

         

        <#if !user.anonymous && page.name == "CommunityPage">
        <#if user.login = "<your name>">
        ${http.response.replaceQuilt("CommunityPage","CommunityPage.Music")}
        </#if>
        </#if>
    • PerBonomi's avatar
      PerBonomi
      Boss

      Why did I now you'd be the first reply? ;)

       

      Sure can!

       

      I want to replace the main community page, the front page. But, I want to test it on a few users first. I can't,however, seem to use Freemarker to change the Page, based on something like role.

      • VarunGrazitti's avatar
        VarunGrazitti
        Boss

        Hahaha :) 

         

        I am not sure if we could change the quilt of a page dynamically, but you mentioned that page initialization will let you change the quilt, thats great. You can add the code which triggers this action in the page initialization tab itself, what is stopping you?

         

        Code to check the access/ role for the users could be something like this:

         

        Create a macro to check the user roles, named access.check.macro

         

        <#assign change_quilt = false />
        <#attempt>
        	<#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 == "REQUIRED_ROLE_1") || role.name?? && (role.name == "REQUIRED_ROLE_2") >        
        			<#assign change_quilt = true />
        		</#if>
        	</#list>
        <#recover>
        	<#assign change_quilt = false />
        </#attempt>	

         

        In the page initialization tab, you could add your code as:

         

         

        <#include "access.check.macro.ftl"> // include the macro in the page initialization tab, so the users role is checked on the page load.
        <#if user.registered> 
        	<#if change_quilt>
        		<#if page.name == "CommunityPage" && http.request.url?index_of("/t5/") lt 0>
        			//Display the other quilt
        		</#if>		
        	</#if>
        </#if>

         

        I hope this helps.