I'm in the process of building some templates for Joomla, and although it all works as desired, I can't help thinking that there has to be a more elegant way to do this in PHP than my current approach. For the record, I'm still reasonably new to PHP!
Using collapsible module positions, I need to assign various CSS classes to a div depending on how many modules are published on a particular row. The code I wrote is below;
if (($footer1 != "0") && ($footer2 == "0") && ($footer3 == "0")) {
$footerWidth = 'full';
}
elseif (($footer1 == "0") && ($footer2 != "0") && ($footer3 == "0")) {
$footerWidth = 'full';
}
elseif (($footer1 == "0") && ($footer2 == "0") && ($footer3 != "0")) {
$footerWidth = 'full';
}
elseif (($footer1 != "0") && ($footer2 != "0") && ($footer3 == "0")) {
$footerWidth = 'one_half';
}
elseif (($footer1 != "0") && ($footer2 == "0") && ($footer3 != "0")) {
$footerWidth = 'one_half';
}
elseif (($footer1 == "0") && ($footer2 != "0") && ($footer3 != "0")) {
$footerWidth = 'one_half';
}
else {
$footerWidth = 'one_third';
}
I then use the following code in the template itself to check for modules published;
<?php if ($footer1 > 0) : ?>
<div class="<?php echo htmlspecialchars($footerWidth); ?>">
<jdoc:include type="modules" name="footer1" style="html5" />
</div>
<?php endif; ?>
<?php if ($footer2 > 0) : ?>
<div class="<?php echo htmlspecialchars($footerWidth); ?>">
<jdoc:include type="modules" name="footer2" style="html5" />
</div>
<?php endif; ?>
<?php if ($footer3 > 0) : ?>
<div class="<?php echo htmlspecialchars($footerWidth); ?>">
<jdoc:include type="modules" name="footer3" style="html5" />
</div>
<?php endif; ?>
Can anyone suggest / recommend a better approach? It just seems like a lot of code for a simple function.