mosLoadModules - An Explanation
Written by Cory |
September 13, 2006
|
(0)
At the Joomla! help site, there is a great article explaining the various functions to be used in a Joomla! template. It gives an explanation of the parameters involved in the mosLoadModules function, which often cause confusion for new template developers. You can either read that article, or if you don't feel like leaving this page, you can continue reading this article, which will explain the same concepts.
Here is the basic syntax of a mosLoadModules function call:
mosLoadModules( $position_name [, $style] )
$position_name
This parameter is pretty self-explanatory. It tells Joomla! where to display your modules.
$style
This is the parameter that causes some confusion. While $position_name tells Joomla! where to position a set of modules, $style tells Joomla! how to render the modules at $position_name. This parameter is optional. If you do not put a value for $style, it will default to $style=0.
There are 5 possible values for $style: 0, 1, -1, -2, -3. Below is an explanation of each value.
$style = 0
As I mentioned, this is the default value for $style. I personally never use this value because it renders each module in a table, and I don't like tables.
Here is how the code is rendered using $style=0.
NOTE: Copied directly from Joomla! help site article
<!-- Individual module --> <table cellpadding="0" cellspacing="0" class="moduletable[suffix]"> <tr> <th valign="top">Module Title</th> </tr> <tr> <td> Module output </td> </tr> </table> <!-- Individual module end -->
$style = 1
This is another value that I personally never use for the same reason as mentioned for $style=0. This $style renders each individual module the same as $style=0, but it wraps the modules in another table and displays them horizontally for that position.
Here is how the code is rendered using $style=1.
NOTE: Copied directly from Joomla! help site article
<!-- Module wrapper --> <table cellspacing="1" cellpadding="0" border="0" width="100%"> <tr> <td align="top"> <!-- Individual module --> <table cellpadding="0" cellspacing="0" class="moduletable[suffix]"> <tr> <th valign="top">Module Title</th> </tr> <tr> <td> Module output </td> </tr> </table> <!-- Individual module end --> </td> <td align="top"> <!-- ...the next module... --> </td> </tr> </table>
$style = -1
Now we're getting to the good stuff. This $style tells Joomla! to just display the raw ouput of the module without the module's title. This can be very useful for displaying things like horizontal menu bars, because you do not need a title, and you probably want to handle the HTML around your menu in your template.
Here is how the code is rendered using $style=-1.
NOTE: Copied directly from Joomla! help site article
Module 1 OutputModule 2 OutputModule 3 Output
Notice here that there are 3 modules in this module position: "Module 1 Output", "Module 2 Output", and "Module 3 Ouput". Notice also that there is no space between "Output" and "Module" where the modules touch each other. That is because Joomla! does not do anything but place the raw output from each module.
$style = -2
When designing a template, this is perhaps the module position $style that I use most often. It renders modules the way modules should be rendered, within a DIV block with the title set apart by the H3 tag. This is the best solution for creating a template with proper modern XHTML/CSS techniques.
Here is how the code is rendered using $style=-2.
NOTE: Copied directly from Joomla! help site article
<!-- Individual module --> <div class="moduletable[suffix]"> <h3>Module Title</h3> Module output </div> <!-- Individual module end -->
$style = -3
This $style is good for performing some CSS styling tricks with your template. For example, if you want to display your modules with rounded corners, you could use this $style along with some CSS. It is basically the same as $style=-2 but it adds 3 "padding" DIV's around the output to enable designers to perform their CSS magic.
Here is how the code is rendered using $style=-3.
NOTE: Copied directly from Joomla! help site article
<!-- Individual module --> <div class="module[suffix]"> <div> <div> <div> <h3>Module Title</h3> Module output </div> </div> </div> </div> <!-- Individual module end -->
What does it all mean?
Joomla! is a flexible system, and it provides several options for designers to render modules. With the addition of CSS, the options are virtually limitless.
Trackback(0)
Comments (29)
written by Cory, November 02, 2006
written by James, December 18, 2006
* yeah I can see the problems with tables but I've only just learnt how to do that much and the idea of rewriting my site to use is quite scary right now - any good pointers to a good tutorial on how "div" works, I can't seem to grasp that concept, while a table is at least quite intuitive. i need that "ah" moment with "div" i just had with "td" et al!
cheers for the tutorial anyway.
written by James, December 24, 2006
I'm thinking it's maybe not a good idea to mix CSS and tables? if you look at www.blueskieschina.com in safari & firefox it looks ok. But in IE, somehow the browser doesn't like my code (and to "debug" is a ten minute walk to my girlfriend's PC... the dog likes this stage of the development!). Maybe I should be braver than just using DIV the once...? But if I could understand WHY IE is doing this, I'd feel a lot more comfortable. I did put a nbsp in the table cell. Stumped for now.
Have a good Christmas!
Cheers
James
written by mark, January 18, 2007
In my template no style is specified, so I guess there is a 'default' style. Looks like:
mosLoadModules ( "right" );
So which is the default style?
Thanks,
Mark
written by Brock McGee, May 20, 2007
Where does one set the suffix to -3 and what is that other gibberish mean here:
Module Title
Module output
??? That looks like it defines rounded corners for only one module at a time. Will this work for all of my modules or only ones in a particular position or with a particular name. Where would I put this code? At what point is the -3 parameter even defined within this?
Sorry, I think one must be well versed in code to understand this. I'm afraid I'm not.
written by bram, July 25, 2007
I'm using mosLoadModules( 'left', -2 ); in my template, but Joomla keeps on generating tables instead of divs.
I'm looking for a solution, but cant find any. Is there another variable I need to set in order to get rid of tables?
Thanks,
Bram
written by Max, August 16, 2007
As an o l d hack I really appreciate your work, enthusiasm and the fact that you put your church and faith out there on your site ... Thanks. God Bless and keep up the good work.
written by aravind, September 20, 2007
use that template using CMS
written by Marco, September 24, 2007
However can you please recommend the best way to horizontally place two or more modules in the same position ie. advert, without any space between the two modules. What is the best way to go about doing this.
Thanks in advance.
written by Den, October 04, 2007
written by akin mayor, March 17, 2008
Your article made a very interesting readig to me and I have learnt a lot from it. I hiwever still need your guidance in line with the following:
1. When I code mosLoadModules("left"), how do I determine which modules are located in this 'left position?
2. Also, how do I place a new module (written by me eg. calendar) in one of the positions 'left', 'right', 'user1' etc. ?
Thanks.
-- Akin
written by Sina, March 27, 2008
This article is excellent for beginners such as myself. My question is the same as Marco's. How do I get 2 modules to occupy the same position, such as having one float right and the other centered? Is this even possible?
Thanks!
--Sina
written by Angela, August 21, 2008
Thanks.
written by mark weatherill, November 26, 2008
Thanks for the helpful articles. I am a Joomla beginner and am trying to create a custom template consisting of a header image at the top, under which is a row of buttons ('About', 'Contact', 'Callback', 'News', etc).
Under that is the main content area and then at the bottom the footer image.
In the Site Modules page, i have all modules unpublished except for 'Top Menu', which has a position of 'top'.
In the 'Menu Manager' [topmenu] page i have two menu items.
In the index.php file in the templates/mywebsite directory, i have the following :
The problem is this: the two menu items are rendering as hyperlinks and i'd like to make them buttons. Where do you do the requisite styling?
Cheers,
Mark Weatherill.
p.s. am using Joomla! 1.0.15, a Xitami web server and Vista.
Write comment
Join the HowToJoomla Community!
- Create a profile
- Connect with other members
of the community - All for FREE
Already a member? Login here.



mosLoadModules( $position_name [, $style] )
However, I'm thinking you meant to have:
mosLoadModules( $position_name , [$style] )
instead?