Forum Discussion

Wendy_S's avatar
11 years ago

remove IF Statement from custom component

I logged the ticket below as a support ticket but actually thought I might share here as well since I believe you folks may be able to help, give inputs (and maybe you are part of the same support team anyway)

Thanks!
Wendy

 

 

 

Hello Lithium team.

In our communities we have 2 unanswered widgets, custom components, created in the past with the help of Lithium. At that time we only wanted to display these components so a Role IF statement has been entered. Now, we want to display this component to all users who are logged in to the forum so we want to remove the roles specified.

Question is, how to best go about this. Can we for example replaces the roles mention with the role REGISTERED USER or should the if statement be removed completely.

This is the code for the component on the forum home page

<#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 == "PHD" || role.name == "Ambassador" || role.name == "Administrator")>
<#assign user_has_role = true />
</#if>
</#list>
</#if>
<#if user_has_role >
<p><a href="http://h30434.www3.hp.com/t5/forums/searchpage/tab/message?sort_by=-topicPostDate&amp;advanced=true&amp;search_type=thread&amp;search_page_size=10&amp;openresponse=true&amp;filter=openResponse" target="_self">Unanswered Posts</a></p>
</#if>

This is the code for the component on the forum Board page.

<#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 == "PHD" || role.name == "Ambassador" || role.name == "Administrator" || role.name == "Super User")>
<#assign user_has_role = true />
</#if>
</#list>
</#if>

<#if user_has_role >
<div class="lia-panel lia-panel-standard unanswered-posts">
<div class="lia-decoration-border">
<div class="lia-decoration-border-top">
<div> </div>
</div>
<div class="lia-decoration-border-content">
<div>
<div class="lia-panel-heading-bar-wrapper">
<div class="lia-panel-heading-bar">
<span class="lia-panel-heading-bar-title">${text.format("unanswered-posts.head.title")}</span>
</div>
</div>
<div class="lia-panel-content-wrapper">
<div class="lia-panel-content">
<div class="lia-button-group">
<span class="lia-button-wrapper lia-button-wrapper-secondary lia-component-forums-action-escalate-message-button">
<div class="lia-button lia-button-secondary escalate-message">
<a href="/t5/forums/searchpage/tab/message?sort_by=-topicPostDate&amp;advanced=true&amp;search_type=thread&amp;search_page_size=10&amp;openresponse=true&amp;filter=openResponse" target="_self">${text.format("unanswered-posts.button.title")}</a>
</div>
</span>
</div>

</div>
</div>
</div>
</div>
<div class="lia-decoration-border-bottom">
<div> </div>
</div>
</div>
</div>

</#if>


Thanks in advance for your help.
Wendy

  • As HaidongG  mentioned, you could use macros and functions as well, but as this is not too bigger a code, you could just remove the If conditions, and it'd work just fine. After stripping off the code in red and putting the line in green inside the if block;

     

    <#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 == "PHD" || role.name == "Ambassador" || role.name == "Administrator")> 
                 <#assign user_has_role = true /> 
            </#if> 
           </#list> 
    </#if> 
    <#if user_has_role > 
    <p><a href="http://h30434.www3.hp.com/t5/forums/searchpage/tab/message?sort_by=-topicPostDate&amp;advanced=true&..." target="_self">Unanswered Posts</a></p> 
    </#if> 

     

    you'll be left with below.

     

    <#if user.registered > 
            <p><a href="http://h30434.www3.hp.com/t5/forums/searchpage/tab/message?sort_by=-topicPostDate&amp;advanced=true&..." target="_self">Unanswered Posts</a></p> 
    </#if> 

     

  • Wendy_S  here you go :)

     

    <#if user.registered > 
    	<div class="lia-panel lia-panel-standard unanswered-posts"> 
           <div class="lia-decoration-border"> 
            <div class="lia-decoration-border-top"> 
         <div> </div> 
           </div> 
           <div class="lia-decoration-border-content"> 
      <div> 
    <div class="lia-panel-heading-bar-wrapper"> 
    <div class="lia-panel-heading-bar"> 
    <span class="lia-panel-heading-bar-title">${text.format("unanswered-posts.head.title")}</span> 
    </div> 
    </div> 
    <div class="lia-panel-content-wrapper"> 
    <div class="lia-panel-content"> 
    <div class="lia-button-group"> 
    <span class="lia-button-wrapper lia-button-wrapper-secondary lia-component-forums-action-escalate-message-button"> 
    <div class="lia-button lia-button-secondary escalate-message"> 
    <a href="/t5/forums/searchpage/tab/message?sort_by=-topicPostDate&amp;advanced=true&amp;search_type=thread&amp;search_page_size=10&amp;openresponse=true&amp;filter=openResponse" target="_self">${text.format("unanswered-posts.button.title")}</a> 
    </div> 
    </span> 
    </div> 
    
    </div> 
    </div> 
    </div> 
    </div> 
    <div class="lia-decoration-border-bottom"> 
    <div> </div> 
    </div> 
    </div> 
    </div> 
    </#if>