Forum Discussion

jmurray's avatar
jmurray
Champion
12 years ago

getting a module to disappear itself when it's empty

I have a piece of custom content that serves as an unsolved threads module.  Works great except that once everything's solved, it's an ugly, empty, useless box.

 

I am trying to figure out how to code an ITE statement that says "If this is empty, self-destruct the custom content module."

 

The part I am stuck on is determining how it's empty.

 

The call being made to get the results is:

<#assign rest_query = "/boards/id/*my node id*/search/messages?openresponse=true&sort_by=-topicPostDate&include_forums=true&page_size=" + results_list_size/>

 

What do I need to make as the criteria in the IF statement for "If *whatever this is is empty*..."

  • It looks like you are relying on the "forums.widget.message-list-panel" component to do the actual REST query, and you want to determine before rendering that component whether or not to display it.  You could use the same query, but with a /count at the end of the path, to determine if there will be any results -- something like this:

     

    <#assign rest_count_query = "/boards/id/ent5/search/messages/count?openresponse=true&sort_by=-topicPostDate&include_forums=true&page_size=" + results_list_size/>
    
    <#assign rest_count = rest(rest_count_query).value />
    <#if rest_count?number gt 0>
      <#-- call the forums.widget.message-list-panel component -->
    </#if>

     

  • There is ?solved=true but that will only return you solved threads. It is a filter on all messages. Unfortunately, that means that ?solved=false doesn't get you all unsolved threads. It just gets you all threads (same as what you have without anything in the query string). I would add an idea to have either ?solved=false return unsolved threads or a new filter ?unsolved=true.
  • ChiaraS's avatar
    ChiaraS
    Lithium Alumni (Retired)

    You can change the code to something like this:

    <#assign rest_query = rest("/boards/id/*my node id*/search/messages?openresponse=true&sort_by=-topicPostDate&include_forums=true&page_size=" + results_list_size).messages />
    <#if rest_query?? && rest_query?size gt 0>
    <#-- do something -->
    </#if>

     

    You may need to change from custom content to custom component (I think that the border for the custom content is always shown if there is some content).

    • jmurray's avatar
      jmurray
      Champion

      I'm closer than I was before, but I keep getting "Expected extended-hash or sequence"on the suggested 

      <#if rest_query?? && rest_query?size gt 0>

      line with this code:

       

      <html>
      <head>
      <style>
      .MessageStatusIcon {float:left; padding-right:7px; clear:both;}
      .MessageSubjectCell {padding-left:7px;}
      .clearfix {display: inline-block;}
      div.lia-panel.lia-panel-standard.UnsolvedSide-wrapper {width:100%;}
      div.lia-panel.lia-panel-standard.UnsolvedSide-wrapper.noneDisplayed {display:none;}
      </style>
      </head>
      <body>
      <#assign message_list_title = text.format("custom.UnsolvedSide.title")/>
      <#assign results_list_size = 5 />
      <#assign rest_query = "/boards/id/ent5/search/messages?openresponse=true&sort_by=-topicPostDate&include_forums=true&page_size=" + results_list_size/>
      <#if rest_query?? && rest_query?size gt 0>
      <div class="lia-panel lia-panel-standard UnsolvedSide-wrapper" id="knowTheAnswer" style=float:left; padding-left:7px; white-space:nowrap; overflow:wrap; width:200px;>
      	<@component id="forums.widget.message-list-panel" title="${message_list_title}" messages="rest_v1:"+rest_query style="slim" numMessages="conv:"+results_list_size/>
      </div>
      <#else>
      <div class="lia-panel lia-panel-standard UnsolvedSide-wrapper noneDisplayed" id="knowTheAnswer" style=float:left; padding-left:7px; white-space:nowrap; overflow:wrap; width:200px;>
      	<@component id="forums.widget.message-list-panel" title="${message_list_title}" messages="rest_v1:"+rest_query style="slim" numMessages="conv:"+results_list_size/>
      </div>
      </#if>
      </body>
      </html>

       Any suggestions?  This probably isn't the most elegant way of doing it, but the idea here is to just make it invisible if it's empty.  The class works if you apply it manually in Firebug.

      • DougS's avatar
        DougS
        Khoros Oracle

        It looks like you are relying on the "forums.widget.message-list-panel" component to do the actual REST query, and you want to determine before rendering that component whether or not to display it.  You could use the same query, but with a /count at the end of the path, to determine if there will be any results -- something like this:

         

        <#assign rest_count_query = "/boards/id/ent5/search/messages/count?openresponse=true&sort_by=-topicPostDate&include_forums=true&page_size=" + results_list_size/>
        
        <#assign rest_count = rest(rest_count_query).value />
        <#if rest_count?number gt 0>
          <#-- call the forums.widget.message-list-panel component -->
        </#if>