per camos request:
I use two methodologies, each dependent upon the site it is deployed on. On some sites, in particular where a lot of custom development is taking place, I use the method of setting a variable with the code used to display a page. This could be adapted via mosaddphp or a custom mambot to also be used in moscontent. Since the execution of the component code takes place before the template is called, setting this varible within the component code itself works very well.
The objective is to set a global variable that the template switches on. If the global variable does not exist, the default portion of the switch statement is used. On the example below (div based template) the left column is eliminated and the component (or mainbody rendering) has a full width single column.
This is on a Real Estate website, and is used for a few selective screens where full width is required for the content. Site is
http://mlshomequest.com and this global variable is used to display the initial search screen for the "MLS property search" in the horizontal menu at the top. Global variable is $sw.
Index.php, after header and pathway code, preceeding footer code. The code is messy, as it has evolved along with the needs on the website and many areas have been commented out:
Code: Select all
<?php
if (isset($GLOBALS['refo_template'])) {
$sw = $GLOBALS['refo_template'];
} else {
$sw = $option;
}
switch ($sw) {
//case 'com_simpleboard':
//case 'com_staticxt':
case 'wide':
echo '<div style="margin:0px;padding:0px;border:0px;width:100%;">';
break;
default:
?>
<div style="float:left;width:150px;padding:0px;border:0px;/*background:position:absolute;top:37px;*/">
<?php if ( mosCountModules( 'left' ) > 0 ) { ?>
<div class="blue" style="float:left;margin-top:0px;/*0px;padding:0px;background-color:#F4F0DF;border:1px solid #673D19;*/">
<?php mosLoadModules ( 'left' ); ?>
</div>
<?php }; ?>
<?php if ( mosCountModules( 'user1' ) > 0 ) { ?>
<div class="tan" style="float:left;margin-top:6px;/*padding:0px;background-color:#F4F8F4;border:1px solid #9966CC;*/">
<?php mosLoadModules ( 'user1' ); ?>
</div>
<?php }; ?>
<?php if ( mosCountModules( 'user2' ) > 0 ) { ?>
<div class="blue" style="float:left;margin-top:6px;/*padding:0px;background-color:#F4F4F8;border:1px solid #6699CC;*/">
<?php mosLoadModules ( 'user2' ); ?>
</div>
<?php }; ?>
<?php if ( mosCountModules( 'bottom' ) > 0 ) { ?>
<div class="tan" style="float:left;margin-top:6px;/*padding:0px;background-color:#F8F4F4;border:1px solid #CC6699;*/">
<?php mosLoadModules ( 'bottom' ); ?>
</div>
<?php }; ?>
</div>
<div style="float:right;/*width:590px;*/width:594px;overflow:hidden;/*margin-left:156px;margin-right:0;*//*width:auto;*//*padding-left:6px;*/padding:0;border:0px;*/">
<?php ;
break;
} ?>
The second method is switching based on $option variable, which allows me to effect the same change when needed for specific components. Site is
http://roadstarclinic.com, and switch takes place for the com_simpleboard component option in the url, same disclaimer as above as the code has been evolving along with the site. This code creates the middle section in the window and footers, and based on switch evaluation either creates a three colum layout, or a two colum layout. Template is table based:
Code: Select all
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<?php switch ($option) {
case 'com_simpleboard':
?>
<?php if ( mosCountModules( 'right' ) > 0 ) { ?>
<td width="135px" align="right" valign="top">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr align="left" valign="top" >
<td height="27" colspan="1" class="mainWindow">
<?php mosLoadModules ( 'right' ); ?>
</td>
</tr>
</table>
<br />
</td>
<?php }; ?>
<td valign="top">
<table width="100%" border="0" margin="0" align="center" cellpadding="5" cellspacing="0" >
<tr valign="top" border="0">
<td height="49" colspan="1" class="mainWindow" >
<table width="97%" height="34" border="0" align="center" cellpadding="0" cellspacing="0">
<?php include ("mainbody.php"); ?>
</td>
</tr>
<?php if ( mosCountModules( 'banners' ) > 0 ) { ?>
<tr>
<td align="center">
<table border="0" cellpadding="0" cellspacing="0" class="moduletable" style="text-align:center;width:480px;padding:5px;margin:10 0 5 0;">
<th align="center"> Road Star Clinic Supporting Sponsor - Please visit our friends at: </th>
<tr valign="top" >
<td height="31" colspan="1" align="center" class="mainWindow">
<?php mosLoadComponent( "banners" ); ?>
</td>
</tr>
</table>
</td>
</tr>
<?php }; ?>
</table>
</td>
</tr>
</table>
<?php
break;
default:
?>
<td width="135px" height="231" align="left" valign="top">
<?php if ( mosCountModules( 'left' ) > 0 ) { ?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr align="left" valign="top" >
<td height="27" colspan="1" class="mainWindow">
<?php mosLoadModules ( 'left' ); ?>
</td>
</tr>
</table>
<?php }; ?>
<?php if ( mosCountModules( 'user1' ) > 0 ) { ?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr align="left" valign="top" >
<td height="27" colspan="1" class="mainWindow" >
<?php mosLoadModules ( 'user1' ); ?>
</td>
</tr>
</table>
<?php }; ?>
<?php if ( mosCountModules( 'user2' ) > 0 ) { ?>
<table width="100%" border="0" cellspacing="0" cellpadding="0" valign="top">
<tr align="left" valign="top" >
<td height="27" colspan="1" class="mainWindow">
<?php mosLoadModules ( 'user2' ); ?>
</td>
</tr>
</table>
<br />
<?php }; ?>
<?php if ( mosCountModules( 'bottom' ) > 0 ) { ?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr align="left" valign="top" >
<td height="27" colspan="1" class="mainWindow">
<?php mosLoadModules ( 'bottom' ); ?>
</td>
</tr>
</table>
<br />
<?php }; ?>
</td>
<td valign="top">
<table width="100%" border="0" margin="0" align="center" cellspacing="0" style="padding:0px 5px 0px 5px;" valign="top">
<tr valign="top" border="0">
<td height="49" colspan="1" class="mainWindow" width="97%" >
<!-- <table width="97%" height="34" border="0" align="center" cellpadding="0" cellspacing="0" valign="top"> -->
<?php include ("mainbody.php"); ?>
<!-- </table> -->
</td>
</tr>
<?php if ( mosCountModules( 'banners' ) > 0 ) { ?>
<tr>
<td align="center">
<table border="0" cellpadding="0" cellspacing="0" class="moduletable" style="text-align:center;width:480px;padding:5px;margin:10 0 5 0;">
<th align="center"> Road Star Clinic Supporting Sponsor - Please visit our friends at: </th>
<tr valign="top" >
<td height="31" colspan="1" align="center" class="mainWindow">
<?php mosLoadComponent( "banners" ); ?>
</td>
</tr>
</table>
</td>
</tr>
<?php }; ?>
</table>
</td>
<!-- </tr>
</table> -->
<?php if ( mosCountModules( 'right' ) > 0 ) { ?>
<td width="135px" align="right" valign="top">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr align="left" valign="top" >
<td height="27" colspan="1" class="mainWindow">
<?php mosLoadModules ( 'right' ); ?>
</td>
</tr>
</table>
<br />
</td>
<?php }; ?>
</tr>
</table>
<?php ;
break;
} ?>
This could be done much more efficiently, but it does work. I worried about the length of the file initially, but as php ignores contents of a switch statement that it does not execute, the longer file added no significant time to a page load.
FWIW.... I clearly am NOT a template designer ::) , these examples are presented as another way to effect template outcome, not as expamles of ideal template coding.
GRAM