[Solved] Hide empty list module

georgie

Member
Hello

I use modules lists to display something like "birtday today", "Recall today"...

Is it possible to hide a module list when the list is empty?

THX
 
There's nothing built in, no.

Are you trying to hide the whole module, or just not show the list if it is empty?

I can't think of any way to entirely not show a module, but you could code something up in Sourcerer (and Modules Anywhere) to only display the module if there are rows to show, although you'd have to do a query by hand ... so run a query by hand to select rows with birthdays today, if it finds rows, then "echo 'module Your Module Name';" ...

Code:
{source}
<?php
$myDb = JFactory::getDbo();
$myQuery = $myDb->getQuery(true);
$myQuery->select('*')->from('mytable')->where('DATE(birthday) = DATE(NOW())');
$myDb->setQuery($myQuery);
$birthdays = $myDb->loadObjectList();
if (!empty($birthdays)) {
   echo "{module Your Birthday Module}";
}
else {
  echo '';
}
?>
{/source}

Actually, that might mean the module doesn't display if you don't output anything if no rows found ... I can't remember if J! bothers rendering a module if it has no content.

-- hugh
 
We are in need of some funding.
More details.

Thank you.
Back
Top