Forum Discussion

Puljac's avatar
Puljac
Maven
12 years ago

Unread messages component

How to make "Unread messages" widget doesn't dissapear and instead of disaapearing to show some custom text like

 

"You have no new unread messages."

 

Thanks

 

  • Hi Puljac,

     

    There's no standard option or setting to enable this type of functionality, but with a little customization you should be able to accomplish this.

     

    This approach will make use of the ability to override standard Lithium components, which you can learn more about here:

    http://lithosphere.lithium.com/t5/support-knowledge-base/Using-override-to-change-core-components/ta-p/61358

     

    Basically what you'll want to do is create a custom component named "forums.widget.unread-messages@override". This will override the standard Unread Messages component. Then, you could add something like this as the content:

    <#assign unreadContent>
    <@delegate />
    </#assign>
    
    <#if unreadContent?? && unreadContent?has_content >
    ${unreadContent}
    <#else>
    You have no new unread messages.
    </#if>

     This first assigns to the variable "unreadContent" the output of the standard component (which is represented here by the "delegate" macro). Next, we check to see if "unreadContent" exists and has any content (basically, is the standard component empty or not). If it has content, we display it. Otherwise, we show the custom message, such as "You have no new unread messages.".

     

    You may need to tweak a bit to add your own content wrapper and style as needed, but hopefully this will get you going in the right direction!

4 Replies

  • AdamN's avatar
    AdamN
    Khoros Oracle
    12 years ago

    Hi Puljac,

     

    There's no standard option or setting to enable this type of functionality, but with a little customization you should be able to accomplish this.

     

    This approach will make use of the ability to override standard Lithium components, which you can learn more about here:

    http://lithosphere.lithium.com/t5/support-knowledge-base/Using-override-to-change-core-components/ta-p/61358

     

    Basically what you'll want to do is create a custom component named "forums.widget.unread-messages@override". This will override the standard Unread Messages component. Then, you could add something like this as the content:

    <#assign unreadContent>
    <@delegate />
    </#assign>
    
    <#if unreadContent?? && unreadContent?has_content >
    ${unreadContent}
    <#else>
    You have no new unread messages.
    </#if>

     This first assigns to the variable "unreadContent" the output of the standard component (which is represented here by the "delegate" macro). Next, we check to see if "unreadContent" exists and has any content (basically, is the standard component empty or not). If it has content, we display it. Otherwise, we show the custom message, such as "You have no new unread messages.".

     

    You may need to tweak a bit to add your own content wrapper and style as needed, but hopefully this will get you going in the right direction!

  • Puljac's avatar
    Puljac
    Maven
    12 years ago
    Wow, didn't expect so quick answer.

    Thank you so much for making an example code and showing me direction ... I will try it tommorow and confirm if it helps.

    Thanks again for help
  • You may find the code below helpful - it displays the normal Lithium private message notification if the user is logged in, and also shows the text "No unread messages" if appropriate.

     

    <#if user.id?number != -1>
      <#assign unreadMessageCount = rest("/users/id/"+user.id+"/mailbox/notes/inbox/unread/count").value />
      <@component id="notes.widget.summary" name="8" panel="false" />
      <#if unreadMessageCount?number < 1 >
        <span class="no-message-message">No unread messages</span>
      </#if>
    </#if>

     

    We use this code in a custom component that we include in the header.

  • Puljac's avatar
    Puljac
    Maven
    12 years ago
    Thanks AdamN & nathan for examples.

    I tried AdamN solution and that's exactly what i needed.

    Need to tweak CSS a bit, but basically thats it.

    Thanks guys