Skip to content

dart-creations.com

Advertisement
Home arrow Joomla arrow Joomla Tips and Tricks arrow #35 - Collapsible Template Positions
Print E-mail

#35 - Joomla Templates - Collapsible Template Positions

Often when designing a Joomla website, you find that there are certain pages where you require certain modules, whilst other pages where these shouldn't be visible. This is easily done via Joomla's functionality of assigning modules to menu item links.

However, this brings about a new problem. The position in the template. How do you create a template which can collapse a module position which is currently not being used? This can be done by counting the number of modules currently assigned to this position by using a few Joomla function calls mosCountModules. An example of this is found below.

<div id="usertoolswrap">
    <div id="usertools">
    <?php if (mosCountModules('user4')) {?>
        <div id="user4">
            <?php mosLoadModules ( 'user4', -1 ); ?>
        </div>
   <?php } ?>
   </div>
 </div>

As we can see, in the code above the user4 position is only rendered when there are modules assigned to position user4. The count modules function allows us only to render the position when modules are assigned to it, and collapses the template position if there are no modules assigned.

Comments
Search RSS
asdf  - asdf   |219.12.52.xxx |2008-06-05 18:57:59
asdfasdf
Umesh   |124.247.192.xxx |2008-07-30 04:44:35
This is a very good article.

But I want to know one more thing that can joomla
provide any function using which we can find the no. of modules at a position on
a page.
e.g. suppose I have a module which will be displayed when we click on a
menu item and position for this is "right". I want to use the space of
position "right" on other menu selection.

Please help.
DART  - Umesh   |Registered |2008-07-30 06:46:27
Yes there are functions to do this. In your template you need to put the
following php code:

mosCountModules('right')

This returns a value of the
number of modules assigned to the right position, and you can perform logic
based on this.
Only registered users can write comments!

3.26 Copyright (C) 2008 Compojoom.com / Copyright (C) 2007 Alain Georgette / Copyright (C) 2006 Frantisek Hliva. All rights reserved."

 

Buy us a beer!

If we've helped you, consider buying a beer €3. It will inspire us to keep on giving! Cheers!


Pagerank
Generated in 0.35919 Seconds