1

I have a custom template that renderes a module in some position. The module does a query to database and renders according to the results. However, if the query to database returns empty rows, module does not have to be shown.

I have this in the template:

                    <!--  lo más de la semana -->
                    <?php if ($this->countModules('lo-mas') > 0): ?>
                        <div class="row">
                            <div class="lomas"> <h3>LO MÁS DE LA SEMANA</h3></div>
                            <jdoc:include type="modules" name="lo-mas" />
                        </div>
                    <?php endif; ?>
                    <!-- fin lo más de la semana -->

I can have several modules at "lo-mas" position, but if, for some reason, all of the modules does not render any output, I don't want the title to be shown ("LO MÁS DE LA SEMANA")

Is this possible in Joomla 3?

jstuardo
  • 3,901
  • 14
  • 61
  • 136
  • Did you make this work with my answer below? – jonasfh Aug 19 '16 at 08:44
  • No.... with that code, an error 500 was displayed. Unfortunately I could not see what exact error occured since Joomla does not log it. Apache did not log the error either. I can check that the jimport instruction was causing the problem. What problem exactly? I could not know. – jstuardo Aug 22 '16 at 13:08
  • OK. It works fine for me, dont know why it does not for you. You'll probably need some minimal PHP experience to figure this out. There is not really a reason there should be an error, unless you messed up the `` -tags. – jonasfh Aug 22 '16 at 13:58
  • I have over 15 years experience in PHP and .NET development. The fact is that I dont have time to try to figure this out. If a solution does not work at first, it is not a real solution – jstuardo Aug 22 '16 at 15:09
  • OK, good luck with that – jonasfh Aug 24 '16 at 06:27

1 Answers1

1

I think you can solve this by rendering the modules a little more manually:

<?php
jimport( 'joomla.application.module.helper' );
$modules = JModuleHelper::getModules( 'lo-mas' );
$output = ''; 
foreach ($modules as $module) {
  $output .= JModuleHelper::renderModule($module);
}
if (trim($output)){ 
?>
<div class="row">
  <div class="lomas"> <h3>LO MÁS DE LA SEMANA</h3></div>
  <?php echo $output; ?>
</div>
<?php
}
?>

You can probably decide exactly how your modules are rendered by specifying the style somehow (usually xhtml), and applying some more html-code to the output...

jonasfh
  • 4,151
  • 2
  • 21
  • 37