Layouts
Component ID
Component name
Component type
Maintenance status
Development status
Component security advisory coverage
Downloads
Component created
Component changed
Component body
Layouts is no longer supported. Drupal 8 will probably support a similar function in core. For layouts in your site in Drupal 7, try Display Suite or Panels
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
Layout uses the theme system to render layout templates, however not all theme properties are supported.
API
Get a list of all available layouts
layouts_get_layouts();
Get information about a specific layout
layouts_get_layout_config();
Define one or more layouts
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' ...
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
$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
$my_layout->content($layout_region_name, $my_content);
Assemble the layout for rendering
$my_layout->build();
Render (or return) the fully-rendered layout
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.
$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;
