websphere-portalwcm

Hiding a Web Content Viewer JSR 286 Portlet if no content is found


I have configured a JSR 286 portlet on my portal page which points to a content item. The content item has an expiry date. Once the content expires the user sees default warning message saying no content found for the selected site area.

I want this portlet should not be rendered if there is no content in the selected site area instead of showing a warning.


Solution

  • Use a Menu Component that is set to only display 1 item for your portlet. Then create a second content item that has a Presentation Template that just says something like this:

    <div class="emptyPortlet" style="display:none;"> This is an empty template. </div>
    

    *if you don't want to declare the style inside the tag, you could also specify .emptyPortlet { display: none;} inside your CSS file.

    Publish this before your other item and then set the Menu Component to display based on Publish Date. This way, when you create another item that you want to display (which uses a different Presentation Template), it will have a more recent publish date and will be shown on the page. But, once that is expired, the only published item left to find will be this blank one, and with "display: none" it will essentially hide the entire portlet from the user.