Hide Hikashop Content Module if empty

  • Posts: 200
  • Thank you received: 75
6 years 9 months ago #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 "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:

<?php if($this->countModules('sidebar')): 
	echo '<div class="sidebar"> /* OUTPUT MODULE HERE */ </div>';
endif; ?>
The recent products work fine, but unfortunately the sidebar is always showing, even if there are no recently viewed products, $this->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 or Create an account to join the conversation.

  • Posts: 4519
  • Thank you received: 612
  • MODERATOR
6 years 9 months ago #274252

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: 6 years 9 months ago by Philip.

Please Log in or Create an account to join the conversation.

  • Posts: 200
  • Thank you received: 75
6 years 9 months ago #274260

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

if($this->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!

Attachments:
Last edit: 6 years 9 months ago by GW.

Please Log in or Create an account to join the conversation.

  • Posts: 81540
  • Thank you received: 13071
  • MODERATOR
6 years 9 months ago #274262

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->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
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 or Create an account to join the conversation.

  • Posts: 200
  • Thank you received: 75
6 years 9 months ago #274323

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->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:

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

Kind regards,

Please Log in or Create an account to join the conversation.

  • Posts: 81540
  • Thank you received: 13071
  • MODERATOR
6 years 9 months ago #274326

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 or Create an account to join the conversation.

Time to create page: 0.070 seconds
Powered by Kunena Forum