Some short initial comments :
1. Why not using an inline css style ?
Instead of doing
Code:
<div id="user1" class="count<?php echo $total ;?>">
You could so :
Code:
<div id="user1" style="width: <?php echo 100/$total ?>%">
This means you can remove all of the extra css.
2. There is no need to make two calls to countModules you can do :
Code:
<?php if ($total = $this->countModules('user1')) : ?>
<div id="top-user-modules" class="clearfix">
<div class="inside">
<div id="user1" class="count<?php echo $total ;?>">
<jdoc:include type="modules" name="user1" style="xhtml" />
</div><!-- end user1 -->
</div><!-- end inside -->
</div><!-- end top-user-modules -->
<?php endif; ?>
This spares you an extra call and makes the code more readable.
3. Instead of doing all this wrapping in your template you could write a special chrome function that wraps your module and does the hard work for you, example :
Code:
<?php if ($this->countModules('user1')) : ?>
<jdoc:include type="modules" name="user1" style="xhtm mystyle" count="<?php echo $total ?>" id="user1">/>
<?php endif; ?>
You will now need to create a custom modules.php file, add it to your termplate/html folder (see also the system template). The file will need to contain the following function :
Code:
function modChrome_mystyle($module, &$params, &$attribs)
{ ?>
if (!empty ($module->content)) : ?>
<div id="top-user-modules" class="clearfix">
<div class="inside">
<div id="<?php echo $attribs['id'] ?>" class="count<?php echo $attribs['count'] ;?>">
<?php echo $module->content; ?>
</div><!-- end user1 -->
</div><!-- end inside -->
</div><!-- end top-user-modules -->
<?php endif;
}
This shows the true power of jdoc:include in action, take special note how the modules count is passed to the chrome function and used to calcumate the width of the module on the fly. This technique keeps you template code very lean and mean and allows you to create re-usable module wrappers.
Hope this helps.
PS. I have not tested the code, it should work though.
Update I : made small change to the code to make it more flexible.
Update II : changed style="mystyle", to style="xhtml mystyle" to demonstrate cascading effect on module styles