When designing our Mambo template we often wish to make provision for modules that may not always have content to display. Through the use of a Mambo function we are able to display these modules only when there is content to display on our site.
For example, if we intend to use banners or other advertising, but don't yet have any advertisers for our sites, we need to provide a spot for these to display once we have a banner to show, but we don't want an empty module position appearing before then. You will see example of this in the default Mambo templates.
To do this, we use a Mambo function named mosCountModules. Using this function in our templates tells Mambo, "if there is content in this module, then display it, otherwise just ignore it".
Example:
<?php if (mosCountModules('banner') >= 1)
{ ?>
<!-- start banner. -->
<div id="banner">
<?php mosLoadModules('banner'); ?>
</div> <!-- end banner. -->
<?php } ?>
This says, "if Mambo sees there is one or more banners to display, then load the banner module position" and if there is not >=1 banner then the module position will not be loaded at all.
In simpler terms..
Example:
<?php if (mosCountModules('banner') >= 1) { mosLoadModules('banner'); } ?>
Note: this code can be used for any module position, including your own custom positions.
If you enjoyed this post, make sure you subscribe to my RSS feed!














{ 1 comment… read it below or jump to the comment form to share your opinion }
thanks elpie...
Leave a Comment