At jfoobar labs you will find "stuff" that is either cool, useful or for learning purposes. We hope to create a pretty nice selection over time. Remember, we need it to be fun.
Here's some code you can use in your template index file to switch between different layouts based on the menu tree -> menu item ID. You can do all kinds of funky stuff with this.
You can put layout files in templates/your_template/layouts. The code you can paste in your templates index.php file.
// Get menu vars for switching between layouts
$menus =& JMenu::getInstance('site'); // Full menu object
$active = $menus->getActive(); // Active id
$default = $menus->getDefault(); // Default id
$mitem = $menus->getItem($active->id); // Active menu item object
$mtree = $mitem->tree[0]; // Tree start id
$mparent = $mitem->parent; // Parent id
// Requests
$option = JRequest::getCmd('option');
$view = JRequest::getCmd('view');
$layout = JRequest::getCmd('layout');
$secid = JRequest::getCmd('secid');
$catid = JRequest::getCmd('catid');
$itemid = JRequest::getCmd('Itemid');
/*
* Check if the page requires a special layout
*/
if ($active->id == $default->id) {
/*
* Include home layout if the default ID == The active ID
*/
require( dirname( __FILE__ ).DS.'layouts'.DS.'home.php');
} else {
/*
* Include the default layout if the default ID != The active ID
*/
require( dirname( __FILE__ ).DS.'layouts'.DS.'page_default.php');
}
Copyright © 2008 jfoobar - All Rights Reserved - Joomla! is a registered trademark of Open Source Matters, Inc - Disclaimer
# 1 - Posted by: unleash.it on 2009-11-07 02:59:48
Very cool, I learned a couple new things. But I think it could help a lot of people if you can break it down into a little more detail with some basic descriptions. I know what most of these do (but not sure what default is vs. active... ), but others might not. Also.. if you throw in some user related stuff that would really be handy!
Thx