Forum Discussion

twitchee27's avatar
13 years ago

Hide Logic for Components Behind a Login

Our community content is meant to be accessed behind a login only. However, I have a few components displaying in a logged out state. If I add in the following logic, will it display behind the login only?

 

<#if user.registered>
<@component id="forums.widget.recent-threads" mode="slim"/>
</#if

 

Furthermore, can I apply that same logic to a component that I want to stop displaying after first login? It would be something like this:

<#if.firstlogin or <#if.rank,"newbie" - does this exist?

 

Your help is much appreciated!

  • Yes, the first code example you listed only shows the content/widget to registered users.

     

    If you want to show content only after first login (which might not be the best idea because: a) You can't tell if the user actually read the message & b) the user has no way to come back to read the message again) it's a bit more complex.

     

    I used the following code to show a message only to registered users of the two lowest ranks in our community:

    <#if user.registered >
    	<#assign rank = restadmin("/users/id/${user.id?c}/ranking").ranking />	
    	<#if rank.name?? && ( (rank.name == "New Member") || (rank.name == "Occasional Visitor") )>
                  CONTENT GOES HERE
            </#if>
    </#if>
    
  • Yes, the first code example you listed only shows the content/widget to registered users.

     

    If you want to show content only after first login (which might not be the best idea because: a) You can't tell if the user actually read the message & b) the user has no way to come back to read the message again) it's a bit more complex.

     

    I used the following code to show a message only to registered users of the two lowest ranks in our community:

    <#if user.registered >
    	<#assign rank = restadmin("/users/id/${user.id?c}/ranking").ranking />	
    	<#if rank.name?? && ( (rank.name == "New Member") || (rank.name == "Occasional Visitor") )>
                  CONTENT GOES HERE
            </#if>
    </#if>
    
      • Claudius's avatar
        Claudius
        Boss
        Great I could help. Don't forget to mark my answer as "Accepted solution" if your question has been answered.