Creating a New Layout
Layouts are blocks of code that control the HTML structure of a particular section of the theme rendering. By default, Gantry comes with several layout files, those are:
- body_debugmainbody.php - a layout used for debugging mainbody layout configurations
- body_mainbody.php - the default mainbody layout. This is the layout that controls the mainbody in relation to the sidebars
- doc_body.php - a layout to render the body tag, used in displayBodyTag()
- doc_tag.php - a layout used in the generic rendering of a tag output by the displayClassesByTag() method
- chrome_basic.php - a basic layout for widgets
- chrome_standard.php - the standard layout for widgets
- widget_sidebar.php - the layout for the sidebars
Step 1: Purpose
The default layout that ships with the Gantry framework is designed to be flexible enough to handle the needs of 99% of all possible implementations. However there are occasions when the default HTML structure does not contain all the blocks elements or class names required to realize a particular design. In these rare cases you can utilize the power of the Gantry framework to override the default layout with your own, theme-provided layout. Also certain layouts such as the widget layouts are flexible enough to support your own custom layouts, and you can call them in the same way the default layouts are called.
Step 2: Create/Copy New Layout Files
The simplest way to do this is to copy an existing layout. In this example we'll copy the body_mainbody.php layout, and modify it after. The files are located under:
YOUR_SITE/wp-content/plugins/gantry/html/layouts/
However you do not want to modify the core gantry files. Instead copy the new layout file to:
YOUR_SITE/wp-content/themes/YOUR_THEME/html/layouts
In this case, copy the body_mainbody.php from the core layouts location into the theme layouts location.
Step 3: File Structure
After you have copied the body_mainbody.php file, you can open it up and edit it to suit your needs. By default it looks like this:
<?php
/**
* @version 1.8 November 16, 2010
* @author RocketTheme http://www.rockettheme.com
* @copyright Copyright (C) 2007 - 2010 RocketTheme, LLC
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 only
*
*/
defined('GANTRY_VERSION') or die();
gantry_import('core.gantrybodylayout');
/**
*
* @package gantry
* @subpackage html.layouts
*/
class GantryLayoutBody_MainBody extends GantryBodyLayout {
var $render_params = array(
'schema' => null,
'pushPull' => null,
'classKey' => null,
'sidebars' => '',
'contentTop' => null,
'contentBottom' => null
);
function render($params = array()) {
global $gantry;
$fparams = $this-> _getParams($params);
// logic to determine if the component should be displayed
$display_component = !($gantry->get("component-enabled", true) == false);
ob_start();
// XHTML LAYOUT
?>
classKey; ?>">
schema['mb']; ?> <?php echo $fparams->pushPull[0]; ?>">
<?php if (isset($fparams->contentTop)) : ?>
<?php echo $fparams->contentTop; ?>
<?php endif; ?>
<?php if ($display_component) : ?>
<?php $this->include_type();?>
<?php endif; ?>
<?php if (isset($fparams->contentBottom)) : ?>
<?php echo $fparams->contentBottom; ?>
<?php endif; ?>
<?php echo $fparams->sidebars; ?>
<?php
return ob_get_clean();
}
}
Feel free to edit this file to suit your needs.