View Single Post
Old 15.08.2004, 01:17   #1 (permalink)
Graemezee
Mamber
 
Graemezee's Avatar
 
Join Date: May 2004
Posts: 78
Graemezee is on a distinguished road
Default Multi template hack (sub_template ) will it work in 4.5.1 beta 4

I found a hack that works well in a template I have been developing in 4.5(1.0.9) I am now redeveloping the templates for version 4.5.1

I have been looking at index.php and cannot work out where to insert this:

// akede,2003-09-14: Check the menu for a different template tag 'sub_template'
$menu= new mosMenu( $database );
$menu->load( $Itemid );
$params = mosParseParams( $menu->params );
$template = isset( $params->sub_template ) ? $params->sub_template : 'index.php';

// Make sure all content will be displayed in white layout
if ( $option=='content' && $task!='section' ) {
$template='index2.php';
}

if ( $option=='com_docman' || $option=='com_akogallery' || $option=='com_remository') {
$template='index2.php';
}
// End: akede


Can any on help with where it could be positioned to work in version 4.5.1
I have posted the whole hack below

Regards Graeme


http://forum.mamboserver.com/showthr...light=template
Alex Kempkins (akede) posted a solution for loading a sub_template during the testing of the alpha versions of 4.5. The solution uses the param field for individual menu items. For example if your template directory had three versions of your template's index.php with the names index.php, index2.php, and index3.php, you could...


Add a param for index2.php by entering this in the param field:

sub_template=index2.php

or to call index3.php

sub_template=index3.php

The code from akede below has been adapted for v4.5.1.0.2 and goes near the end of the main index.php in your MOS root directory. Below, look for the areas marked with the akede start and end comments. The balance of the code is for 4.5.1.0.2 and is for reference purposes only to show where the akede code goes:

code:

} else {

// akede,2003-09-14: Check the menu for a different template tag 'sub_template'
$menu= new mosMenu( $database );
$menu->load( $Itemid );
$params = mosParseParams( $menu->params );
$template = isset( $params->sub_template ) ? $params->sub_template : 'index.php';

// Make sure all content will be displayed in white layout
if ( $option=='content' && $task!='section' ) {
$template='index2.php';
}

if ( $option=='com_docman' || $option=='com_akogallery' || $option=='com_remository') {
$template='index2.php';
}
// End: akede

ob_start();
}
header( "Expires: Mon, 26 Jul 1997 05:00:00 GMT" ); // Date in the past
header( "Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT" ); // always modified
header( "Cache-Control: no-store, no-cache, must-revalidate" );
header( "Cache-Control: post-check=0, pre-check=0", false );
header( "Pragma: no-cache" );

// akede,2003-09-14: Check the menu for a different template tag 'sub_template'
require_once( "templates/$cur_template/$template" );
// End: akede

if (!file_exists("templates/$cur_template/index.php")){
echo "Template File Not Found!";
} else {
require_once( "templates/$cur_template/index.php" );
}

if ( $do_gzip_compress )
{
//
// Borrowed from php.net!
//
$gzip_contents = ob_get_contents();
ob_end_clean();

$gzip_size = strlen($gzip_contents);
$gzip_crc = crc32($gzip_contents);

$gzip_contents = gzcompress($gzip_contents, 9);
$gzip_contents = substr($gzip_contents, 0, strlen($gzip_contents) - 4);

echo "\x1f\x8b\x08\x00\x00\x00\x00\x00";
echo $gzip_contents;
echo pack('V', $gzip_crc);
echo pack('V', $gzip_size);
} else {
ob_end_flush();
}

Not all menu items have a params field accessible from Admin. The Typed Content menu item is an example. However, a param field exists in mos_menus for every menu item, so you need to manually add the sub_template argument to the applicable records in mos_menus using phpMyAdmin only for those menu items without an Admin accessible params field. For consistency reasons, it would be nice to see the params field added to all of the menu item types.

The big advantage of this solution in lieu of using separate templates as indicated above is increased loading speed if most of the graphics remain the same because those graphics are already cached. For example, you might want to divide (or rather simulate dividing) your site into groups where you change a site name to reflect the current user community group.
Graemezee is offline   Reply With Quote
Sponsored Links