[Skip to main content](#vessel-content)

#   Hide Hikashop Content Module if empty

##

- **[GW](/forum/user/33851-gw "View GW's Profile")**
- [![GW's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/33851-gw "View GW's Profile") Topic Author
- [ Offline](/forum/user/33851-gw)

Less More

- Posts: 200
- Thank you received: 75
-
-

9 years 3 months ago [\#274219](#274219) by [GW](/forum/user/33851-gw "View GW's Profile")  *[Hide Hikashop Content Module if empty](/forum/32-content-creation/891190-hide-hikashop-content-module-if-empty#274219 "-- HikaShop version -- : 3.1.1 -- Joomla version -- : 3.7.3  Hi,  there've been threads about hiding a cart module if it is empty and you now have the option &quot;Hide if empty&quot;, but we face a similar issue with a Hikashop Content Module for recently viewed products. We wanted to display it in a sidebar, and hide the module position if there are no recent products, using:  The recent products work fine, but unfortunately the sidebar is always showing, even if there are no recently viewed products, $this-&gt;countModules('sidebar') will still always return 1. Also using Advanced Module Manager with the option &quot;Hide if empty&quot; unfortunately doesn't do the trick.  We don't show the module title or anything, the sidebar is completely empty and the Hikashop Content Module appears to output just a single whitespace, so we wanted to ask if there's any way for us to fix this in Hikashop? Thanks for any help!")* was created by *[GW](/forum/user/33851-gw "View GW's Profile")*

-- HikaShop version -- : 3.1.1
-- Joomla version -- : 3.7.3

Hi,

there've been threads about hiding a cart module if it is empty and you now have the option "Hide if empty", but we face a similar issue with a Hikashop Content Module for recently viewed products. We wanted to display it in a sidebar, and hide the module position if there are no recent products, using: Code:

&lt;?php if($this-&gt;countModules('sidebar')): echo '&lt;div class="sidebar"&gt; /* OUTPUT MODULE HERE */ &lt;/div&gt;'; endif; ?&gt;

The recent products work fine, but unfortunately the sidebar is always showing, even if there are no recently viewed products, **$this-&gt;countModules('sidebar')** will still always return 1. Also using Advanced Module Manager with the option "Hide if empty" unfortunately doesn't do the trick.

We don't show the module title or anything, the sidebar is completely empty and the Hikashop Content Module appears to output just a single whitespace, so we wanted to ask if there's any way for us to fix this in Hikashop?
Thanks for any help!

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtL2NvbnRlbnQtY3JlYXRpb24vODkxMTkwLWhpZGUtaGlrYXNob3AtY29udGVudC1tb2R1bGUtaWYtZW1wdHk/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[Philip](/forum/user/34318-philip "View Philip's Profile")**
- [![Philip's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/34318-philip "View Philip's Profile")
- [ Offline](/forum/user/34318-philip)

Less More

- Posts: 4820
- Thank you received: 652
-
-

9 years 3 months ago -  9 years 3 months ago [\#274252](#274252) by [Philip](/forum/user/34318-philip "View Philip's Profile")  Replied by *[Philip](/forum/user/34318-philip "View Philip's Profile")* on topic *[Hide Hikashop Content Module if empty](/forum/32-content-creation/891190-hide-hikashop-content-module-if-empty#274252 "-- HikaShop version -- : 3.1.1 -- Joomla version -- : 3.7.3  Hi,  there've been threads about hiding a cart module if it is empty and you now have the option &quot;Hide if empty&quot;, but we face a similar issue with a Hikashop Content Module for recently viewed products. We wanted to display it in a sidebar, and hide the module position if there are no recent products, using:  The recent products work fine, but unfortunately the sidebar is always showing, even if there are no recently viewed products, $this-&gt;countModules('sidebar') will still always return 1. Also using Advanced Module Manager with the option &quot;Hide if empty&quot; unfortunately doesn't do the trick.  We don't show the module title or anything, the sidebar is completely empty and the Hikashop Content Module appears to output just a single whitespace, so we wanted to ask if there's any way for us to fix this in Hikashop? Thanks for any help!")*

Hello,

Sorry but I'm not sure to follow you, I have ideas but **no certainties**...
In order to be sure to understand you well, can you add some **screenshot** (with annotations) or better an **Url link** to see it by ourself.
Awaiting news from you.

Regards

Last edit: 9 years 3 months ago by [Philip](/forum/user/34318-philip "View Philip's Profile").

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtL2NvbnRlbnQtY3JlYXRpb24vODkxMTkwLWhpZGUtaGlrYXNob3AtY29udGVudC1tb2R1bGUtaWYtZW1wdHk/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[GW](/forum/user/33851-gw "View GW's Profile")**
- [![GW's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/33851-gw "View GW's Profile") Topic Author
- [ Offline](/forum/user/33851-gw)

Less More

- Posts: 200
- Thank you received: 75
-
-

9 years 3 months ago -  9 years 3 months ago [\#274260](#274260) by [GW](/forum/user/33851-gw "View GW's Profile")  Replied by *[GW](/forum/user/33851-gw "View GW's Profile")* on topic *[Hide Hikashop Content Module if empty](/forum/32-content-creation/891190-hide-hikashop-content-module-if-empty#274260 "-- HikaShop version -- : 3.1.1 -- Joomla version -- : 3.7.3  Hi,  there've been threads about hiding a cart module if it is empty and you now have the option &quot;Hide if empty&quot;, but we face a similar issue with a Hikashop Content Module for recently viewed products. We wanted to display it in a sidebar, and hide the module position if there are no recent products, using:  The recent products work fine, but unfortunately the sidebar is always showing, even if there are no recently viewed products, $this-&gt;countModules('sidebar') will still always return 1. Also using Advanced Module Manager with the option &quot;Hide if empty&quot; unfortunately doesn't do the trick.  We don't show the module title or anything, the sidebar is completely empty and the Hikashop Content Module appears to output just a single whitespace, so we wanted to ask if there's any way for us to fix this in Hikashop? Thanks for any help!")*

Hi Philip,

because it doesn't work the way we want to, we haven't got a live URL for you to take a look, but it is quite easy to reproduce, hopefully the attached screenshots will help show the issue. Using the default protostar template, in the first screenshot you can see the pink sidebar on the left showing some recent products we viewed before, this works ok (*edit: after submitting we see the order of the attachments is mixed up, but the images end with 1, 2, and 3*).

If we clean our cache to pretend we're a new user who visits our webshop for the first time, the second screenshot shows what he will see. The sidebar is completely empty as you can also see in the Inspector at the bottom, but it is still showing.

The third screenshot is what we want, for the sidebar to be completely gone when there are no recently viewed products.

In Joomla it is common to hide/display a module position using Code:

if($this-&gt;countModules('sidebar')):

and this works fine for other modules, but not for the Hikashop Content Module. The countModules function will always return 1 with a Hikashop Content Module, even when it doesn't output anything (except some whitespace), as in our second screenshot.

Hopefully this will help to make it more clear, thanks!

- [ ![Hikashop&#95;Module&#95;Recent&#95;Products&#95;2.jpg](/forum/attachment/39254) ](/forum/attachment/39254 "...Products&#95;2.jpg") [ ](/forum/attachment/39254?download=1 "...Products&#95;2.jpg")
- [ ![Hikashop&#95;Module&#95;Recent&#95;Products&#95;3.jpg](/forum/attachment/39255) ](/forum/attachment/39255 "...Products&#95;3.jpg") [ ](/forum/attachment/39255?download=1 "...Products&#95;3.jpg")
- [ ![Hikashop&#95;Module&#95;Recent&#95;Products&#95;1.jpg](/forum/attachment/39256) ](/forum/attachment/39256 "...Products&#95;1.jpg") [ ](/forum/attachment/39256?download=1 "...Products&#95;1.jpg")

Last edit: 9 years 3 months ago by [GW](/forum/user/33851-gw "View GW's Profile").

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtL2NvbnRlbnQtY3JlYXRpb24vODkxMTkwLWhpZGUtaGlrYXNob3AtY29udGVudC1tb2R1bGUtaWYtZW1wdHk/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86556
- Thank you received: 14305
-
-

9 years 3 months ago [\#274262](#274262) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Hide Hikashop Content Module if empty](/forum/32-content-creation/891190-hide-hikashop-content-module-if-empty#274262 "-- HikaShop version -- : 3.1.1 -- Joomla version -- : 3.7.3  Hi,  there've been threads about hiding a cart module if it is empty and you now have the option &quot;Hide if empty&quot;, but we face a similar issue with a Hikashop Content Module for recently viewed products. We wanted to display it in a sidebar, and hide the module position if there are no recent products, using:  The recent products work fine, but unfortunately the sidebar is always showing, even if there are no recently viewed products, $this-&gt;countModules('sidebar') will still always return 1. Also using Advanced Module Manager with the option &quot;Hide if empty&quot; unfortunately doesn't do the trick.  We don't show the module title or anything, the sidebar is completely empty and the Hikashop Content Module appears to output just a single whitespace, so we wanted to ask if there's any way for us to fix this in Hikashop? Thanks for any help!")*

Hi,

That is not something that is handled by HikaShop. HikaShop can only not display any HTML for the output of the module. It's up to the template to not display the position HTML if no module displays anything in the position.

So the problem is with the code in your template.
The check "if($this-&gt;countModules('sidebar'))" is not valid for what you want to do as it only check if at least module is enabled for that position, not if at least a not empty module is enabled for that position.
What you need to do is to replace that check with the proper check:
- you need to first load the modules of that position in a variable
- and then check if that variable is empty or not.
[ joomla.stackexchange.com/questions/4215/...-from-being-rendered](https://joomla.stackexchange.com/questions/4215/how-to-prevent-empty-modules-from-being-rendered)
[ yootheme.com/support/question/12981](https://yootheme.com/support/question/12981)
The best would be to contact the template provider to see what change they recommend for their template in order to support that.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtL2NvbnRlbnQtY3JlYXRpb24vODkxMTkwLWhpZGUtaGlrYXNob3AtY29udGVudC1tb2R1bGUtaWYtZW1wdHk/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[GW](/forum/user/33851-gw "View GW's Profile")**
- [![GW's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/33851-gw "View GW's Profile") Topic Author
- [ Offline](/forum/user/33851-gw)

Less More

- Posts: 200
- Thank you received: 75
-
-

9 years 3 months ago [\#274323](#274323) by [GW](/forum/user/33851-gw "View GW's Profile")  Replied by *[GW](/forum/user/33851-gw "View GW's Profile")* on topic *[Hide Hikashop Content Module if empty](/forum/32-content-creation/891190-hide-hikashop-content-module-if-empty#274323 "-- HikaShop version -- : 3.1.1 -- Joomla version -- : 3.7.3  Hi,  there've been threads about hiding a cart module if it is empty and you now have the option &quot;Hide if empty&quot;, but we face a similar issue with a Hikashop Content Module for recently viewed products. We wanted to display it in a sidebar, and hide the module position if there are no recent products, using:  The recent products work fine, but unfortunately the sidebar is always showing, even if there are no recently viewed products, $this-&gt;countModules('sidebar') will still always return 1. Also using Advanced Module Manager with the option &quot;Hide if empty&quot; unfortunately doesn't do the trick.  We don't show the module title or anything, the sidebar is completely empty and the Hikashop Content Module appears to output just a single whitespace, so we wanted to ask if there's any way for us to fix this in Hikashop? Thanks for any help!")*

Ok, thank you. Because you added the option "hide if empty" for the cart module some time ago, we just wondered if the same could be done for Hikashop Content Modules.

We've been searching for solutions as well and none of the links you gave work for the Hikashop Content Module unfortunately, since they all rely on checking the **$module-&gt;content** parameter which is always empty for this module, even when it does display products.

The only solution as far as we've been able to find, for anyone interested, is to render the module first "behind the scenes" and check if it outputs anything: Code:

if(JModuleHelper::renderModule(reset(JModuleHelper::getModules( 'sidebar' )))!= ""): echo '&lt;div class="sidebar"&gt; /* OUTPUT MODULE HERE */ &lt;/div&gt;'; endif;

Kind regards,

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtL2NvbnRlbnQtY3JlYXRpb24vODkxMTkwLWhpZGUtaGlrYXNob3AtY29udGVudC1tb2R1bGUtaWYtZW1wdHk/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86556
- Thank you received: 14305
-
-

9 years 3 months ago [\#274326](#274326) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Hide Hikashop Content Module if empty](/forum/32-content-creation/891190-hide-hikashop-content-module-if-empty#274326 "-- HikaShop version -- : 3.1.1 -- Joomla version -- : 3.7.3  Hi,  there've been threads about hiding a cart module if it is empty and you now have the option &quot;Hide if empty&quot;, but we face a similar issue with a Hikashop Content Module for recently viewed products. We wanted to display it in a sidebar, and hide the module position if there are no recent products, using:  The recent products work fine, but unfortunately the sidebar is always showing, even if there are no recently viewed products, $this-&gt;countModules('sidebar') will still always return 1. Also using Advanced Module Manager with the option &quot;Hide if empty&quot; unfortunately doesn't do the trick.  We don't show the module title or anything, the sidebar is completely empty and the Hikashop Content Module appears to output just a single whitespace, so we wanted to ask if there's any way for us to fix this in Hikashop? Thanks for any help!")*

Hi,

The thing is that the HikaShop content modules already output no HTML if no products are found.
That option from the cart module was to remove all the HTML of the cart module when the cart is empty, which was not the case otherwise. So there is no need for the same option in the content module as it already has the behavior "hide if empty" of the cart module.
In your template's case, you would have the same empty position issue with the empty cart module, even with the "hide if empty" option turned on.
The problem is not with the module itself.

And yes, pre rendering the module in the code of the template to check if the returned HTML is empty or not is the only way you can solve that. That's what I was recommending in my previous message.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtL2NvbnRlbnQtY3JlYXRpb24vODkxMTkwLWhpZGUtaGlrYXNob3AtY29udGVudC1tb2R1bGUtaWYtZW1wdHk/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

Board Categories HikaShop Install &amp; Update Product &amp; Category Display Content Creation Sales and Orders Orders management Reports &amp; Statistics Customers Checkout Payment Methods Shipping Methods Import &amp; Export (CSV, XLS…) Specific Features Affilation Taxes Wishlist Vote Carousel &amp; Slider Mass Actions Filters &amp; Search Discount &amp; Coupon Feature Request Integrations Showcase General Talk about HikaShop Development HikaShop 3.0 Beta Translation Commercial Jobs HikaShop Components HikaMarket Market: Feature requests Market: How to? Market: Bug Report HikaSerial General talk about HikaSerial Serial: Bug Report Serial: How to? Support en Français de HikaSerial (French Support) HikaSubscription HikaAuction Auction: Feature requests Auction: How to? Auction: Bug report Hikashop around the world Support en Français (French Support) Russian FAQ. Курс выживания с Hikashop. Частые вопросы и о Расширения Hikashop Наши сайты на Hikashop 日本語版サポート(Japanese Support) Thai German Archives Bug Report How to?

[](/forum/topics/feed/mode-topics?format=feed&type=rss)

Time to create page: 0.057 seconds

[Powered by](/forum/credits) [Kunena Forum](https://www.kunena.org)
