Flexible 2/3 column Template

Description

This is a process which allows a template to be 2 OR 3 columns (live) based on what is in the 3rd column. That is, if the 3rd column is empty, it will resize the 2nd column to take up all the available space. (and is adjustable)

Note that in the backend, it will always display 3 columns (or else you might find it difficult to add 3rd column data).

The idea behind this is you can simply give your users 1 template and how it displays is based on how they use it. If you later decide you want a 3rd column, you don't have to change all the pages.

Code

First Step:  Make a 3rd Column Container
In the pre-loop sequence put something like this:
<!-- Inserted Third Column   ${esc.dollar}CONTAINER_NUM_CONTENTLETS -->

${esc.hash}if(${esc.dollar}CONTAINER_NUM_CONTENTLETS > 0 && !${esc.dollar}EDIT_MODE)
<div class="col col-right">
${esc.hash}end  

In the post-loop, put this:
${esc.hash}if(${esc.dollar}CONTAINER_NUM_CONTENTLETS > 0 && !${esc.dollar}EDIT_MODE)
</div>
${esc.hash}set (${esc.dollar}leftcol="col col-left")
${esc.hash}end
<!-- END Inserted Third Column -->


Now, in your template, you need some code as well.
I very specifically created the Edit-Mode state (requiring a duplication of code) versus the Live-Mode - this had to be done because the Edit-Mode site appearance is very difficult to control (because of all the Java/CMS information).  You could get away with less code, but it might change the order of how the editable fields show up in the backend.
You need some styles set up, here I am using 'col col-left' and 'col col-leftfull' to differentiate how the styling with change based on the use of the column.
I also do not use ELSEs within Velocity - they are too easy to accidentally break/follow.


<CLIPPED ONLY TO SHOW post-header template>
<!-- Content -->  
<div id="content">

  ${esc.hash}${esc.hash}IHM - Breadcrumbs
  ${esc.hash}parseContainer('ba5233d7-9768-48b4-993d-30e5189a66b3')

  
  
${esc.hash}${esc.hash}SPECIAL 3rd Column - if no information it is GONE
${esc.hash}${esc.hash}STYLE Col-left is for 3 col, Col-leftfull for 2 col
${esc.hash}${esc.hash}Edit Mode forces how it shows in backend, always 3 col!!!  
${esc.hash}if (${esc.dollar}EDIT_MODE)
 <div class="col col-left">
   <h1>${esc.dollar}pageTitle</h1>
          <div class="cl">&nbsp;</div>
  
             <div class="post">
             ${esc.hash}${esc.hash} Container: Sisters Main Body
             ${esc.hash}parseContainer('71805')
             </div>
</div>
  
  
<div class="col col-right">
${esc.hash}parseContainer('3b8b67fe-9ad2-416d-828c-d8d16f801b66')  
</div>
<div class="cl">&nbsp;</div>  
${esc.hash}end 
${esc.hash}${esc.hash}END of IF EDITMODE 
  
${esc.hash}${esc.hash}Edit here for all 'live' views of the page!!!!  
${esc.hash}if (!${esc.dollar}EDIT_MODE)  
${esc.hash}set (${esc.dollar}leftcol="col col-leftfull")
${esc.hash}${esc.hash} Container: IHM - Right Optional
${esc.hash}${esc.hash} This is autogenerated code that cannot be changed
${esc.hash}parseContainer('3b8b67fe-9ad2-416d-828c-d8d16f801b66')  


${esc.hash}${esc.hash}PARSING THE CONTAINER ABOVE MAY CHANGE ${esc.dollar}leftcol!
${esc.hash}${esc.hash}CHECK THE PRE-CODE in Container 'IHM Right Optional'  
<div class="${esc.dollar}leftcol">
          <h1>${esc.dollar}pageTitle</h1>
          <div class="cl">&nbsp;</div>
  
             <div class="post">
             ${esc.hash}${esc.hash} Container: Sisters Main Body
             ${esc.hash}parseContainer('71805')
             </div>
</div>
  
${esc.hash}end  
${esc.hash}${esc.hash}END SPECIAL 2/3 COLUMN DISPLAY CODE 


</div>
${esc.hash}${esc.hash}end of div id content