2 column template - 1 column width depends if other is empty

Everything to do with Joomla! 3.x templates and templating.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Windows Defender SmartScreen Issues <-- please read this if using Windows 10.
Locked
gavrd1
Joomla! Apprentice
Joomla! Apprentice
Posts: 13
Joined: Mon Jul 13, 2009 5:03 am

2 column template - 1 column width depends if other is empty

Post by gavrd1 » Thu Aug 14, 2014 1:07 am

Hi everyone

I am just working on setting up a template for Joomla and it consists of 2 columns (let's call these LHScol and RHScol) both sat within a container div that is 960px wide.

If both columns were to have content in them then I would want LHScol to be 200px wide and RHScol to be 760px wide. RHScol would then always sit to the right of LHScol no matter the width of the content in RHScol. i.e. it would have a maximum width of 760px.

However, if no content or modules were in LHScol (i.e. it is empty) I would like it to collapse to width 0 and therefore RHScol would then have a maximum width of 960px available.

Is it possible to do this via html/css styling or does it require something more dynamic such as a script to detect the content and resize the columns?

Thanks

imarklee
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 205
Joined: Wed Aug 29, 2012 7:07 am
Location: Kuala Lumpur, Malaysia
Contact:

Re: 2 column template - 1 column width depends if other is e

Post by imarklee » Sun Aug 17, 2014 5:53 pm

If you are doing this in your Joomla template, you can use the @countModules method to count the total number of modules loaded for the particular position.
Lead Developer,
https://stackideas.com

Mr. Wimpy
Joomla! Explorer
Joomla! Explorer
Posts: 448
Joined: Fri Dec 02, 2005 10:46 am
Location: The Netherlands

Re: 2 column template - 1 column width depends if other is e

Post by Mr. Wimpy » Wed Aug 20, 2014 9:59 am

Hey, here's how you can do this:

The html in your index.php

Code: Select all

<?php if($this->countModules('LHSCol')) { ?>
<div class="LHSCol">
<jdoc:include type="modules" name="LHSCol" />
</div>
<?php } ?>

<div class="content<?php if($this->countModules('LHSCol')) { echo " RHSCol"; } ?>">
<jdoc:include type="component" />
</div>
the css

Code: Select all

.LHSCol {
width: 200px;
...
}
.RHSCol {
width: 760px;
...
}
What happens:
When you have set no module in position LHSCol the div with class=LHSCol is NOT displayed, and
the 2nd div only gets class="content".

When you did set a module in position LHSCol the div class=LHSCol is displayed, and
the 2nd div gets class="content RHSCol"

Good luck.


Locked

Return to “Templates for Joomla! 3.x”