Layouts is an API for creating and reusing layouts in HTML. It adds an extra layer of configuration between content and templating functions.
Layouts 1.x
Layouts 1.x is a proof of concept only, however it is functional and in use on one production site. It allows you to
- define a layout through its API
- retrieve a layout in code
- assign content to layout regions
- render a layout
Version 1.x has limited functionality. It uses the theme system to render layout templates, however not all theme properties are supported.
Feature roadmap for Layouts 2.x
- UI module to manage layouts
- Exportable layouts - compatible with Features
- Reuse Panels layouts
- Use Context to select layouts
- Use Rules to select layouts
- Drag-and-drop blocks for layouts
Other ideas
- Integration with Display Suite
API
Get a list of all available layouts
<?php
layouts_get_layouts();
?>Get information about a specific layout
<?php
layouts_get_layout_config();
?>Define one or more layouts
<?php
HOOK_define_layouts();
?>Define one or more layouts to be made available to other modules via the Layouts API.
Here is the example from Layouts, which defines a default, single column layout, rendered using the template 'default_layout.tpl.php' ...
<?php
function layouts_define_layouts(){
return array(
'default' => array(
'#title' => t('Default'),
'#name' => 'default',
'#category' => '',
'#icon' => '',
'#theme' => array(
'layouts_default_layout' => array(
'arguments' => array('regions' => array()),
'path' => 'theme',
'template' => 'default_layout'
),
),
'#regions' => array(
'content' => t('Content'),
)
)
);
}
?>Create a new Layout object
<?php
$my_layout = layouts_load($name, $module = NULL);
?>This expects two parameters, the name of the layout to retrieve, and if that layout is provided by a third-party (e.g. Panels), the module name. This second parameter currently has no effect, but if provided will, in future, trigger Layouts to return the original Layout definition, rather than the normalised Layout definition.
Add content to a layout region
<?php
$my_layout->content($layout_region_name, $my_content);
?>Assemble the layout for rendering
<?php
$my_layout->build();
?>Render (or return) the fully-rendered layout
<?php
echo $my_layout->render();
?>Usage example
The following example creates a new layout using the layout template 'layout_foo', adds content to its regions, and renders it.
<?php
$layout = layouts_load('layout_foo');
$layout->content('header', 'This is my header');
$layout->content('right', 'This is the right column');
$layout->content('left', 'This is the left column')
$layout->add_css($my_module_path.'/layouts/layout_foo/layout_foo.css');
$layout->build();
echo $layout->render;
?>Downloads
Project Information
- Maintenance status: Actively maintained
- Development status: Under active development
- Downloads: 123
- Last modified: April 28, 2011