Forum Discussion

kentgilliam's avatar
12 years ago

Need to generate conditional homepage

We have a current community for one product group but a new product group is buidling another community on our instance. For the most part I am able to separate the two but the Community Browser only links to the main community homepage. I'd like to be able to manage the content for each product group's homepage on a category page and then use a conditional to render the entire content of a page based on role.

 

The conditional would look something like this:

 

<#assign user_has_role = false /> 
<#if user.registered > 
<#list restadmin("/users/id/${user.id?c}/roles").roles.role as role> 
<#if role.name?? && (role.name == "BBCRM")> 
<#assign user_has_role = true /> 
</#if> 
</#list> 
</#if> 

<#if user_has_role > 

This would be code that would generate all of the content under category 1 URL 

<#else> 

This would be code that would generate all of the content under category 2 URL  

</#if> 

 I've looked through Freemarker options and REST API options but I can't figure out anything that works. Is it even possible to bring in the content of a page without using <iframe>? Please tell me there is a way. 

 

Thanks!

Kent

3 Replies

  • I hesitate to offer this as a "solution" as its requires Javascript programming, but you could take a look at the built in component - Common > Site Navigation Drop Down which presents the Community structure a user has access to (based on their role) and also bookmarks. Rather than create your own using REST you could use this component and copy the unordered list from its output and inject this into the DOM elsewhere for styling.    

  • kentgilliam's avatar
    kentgilliam
    Mentor
    12 years ago

    Thanks for the info. I'll test this out and see if it could work.

     

    Kent

  • kentgilliam's avatar
    kentgilliam
    Mentor
    12 years ago

    Wanted to share this in case anyone else is looking for this info:

     

    I didn't do it exactly like the recommendation but I did create a completely conditional homepage that works great and is very easy to manage. The manage part was the part I was worried about. I was able to create three versions of the user-nav, header, footer and left-column custom content box that renders based on someone's role. The challenge is what to do when someone is a member of two roles that each have their own homepage. Here is the code that I used for my conditional header. Basically I created three headers in Custom Components and then I created one Custom Component that is my primary header element. It renders one of the three header options based on the roles. Take a look and let me know if it makes sense or not.

     

    <#assign user_has_role = false />
    <#if user.registered >
    	<#list restadmin("/users/id/${user.id?c}/roles").roles.role as role>
    		<#if role.name?? && (role.name == "BBCRM")>
    			<#assign user_has_role = true />
    		</#if>
    	</#list>
    </#if>
    
    <#if user_has_role >
    
    <@component id="bbcrm.header.component"/>
    						
    
     <#else> 
          
    <#assign user_has_role = false />
    <#if user.registered >
    	<#list restadmin("/users/id/${user.id?c}/roles").roles.role as role>
    		<#if role.name?? && (role.name == "BBRE")>
    			<#assign user_has_role = true />
    		</#if>
    	</#list>
    </#if>
    
    <#if user_has_role >
    
    <@component id="bbre.header.component"/>
    						
    
     <#else> 
          
    <@component id="bblum.header.component"/>
    </#if>
    </#if>