It is already possible to have different page layouts/templates for pages with an existing discovery mechanism for templates. As can be seen in template_proprocess_page() where page template file suggestions such as page__node, page__node__%, page__node__1, and page__node__edit are produced (for a page like node/1/edit. As well as theme(), where the template is chosen based on these suggestions.
It is not currently possible to switch page layouts by any other means such as making it configurable as to which page layouts are used for which paths / path patterns or other conditions, unless there is a module altering ($variables['theme_hook_suggestions']) overriding what the theme provided entirely or sidestepping page themeing altogether.
If we don't want to sidestep theme page templates, making it possible to switch between (potentially exclusively theme provided) layouts requires the theme to provide a list of the layouts included within and Drupal to provide a user interface to switch between them. This issue is about defining the list of layouts provided.
Themes should explicitly declare their page layouts, so instead page.tpl.php (page-node.tpl.php, etc) type of files among other templates, themes would have a layouts subdirectory, which would contain directories for each layout defined. For one layout, the corresponding CSS styles, tpl.php template and possibly an icon for the layout would be contained in this directory as well as a simple .yml file to describe the layout.
As an example with the Bartik theme
- Instead of bartik/templates/page.tpl.php, the template would be at bartik/layout/page/bartik--page.tpl.php (where the layout subdirectory name "page" is arbitrarily picked by the theme and the tpl.php name consists of the theme name and the filename for the .yml, this bartik--page.tpl.php (see the .yml file below)
- Instead of bartik/css/layout.css, the layout style becomes bartik/layout/page/layout.css (or bartik/layout/page/page.css), again the file name is declared in the .yml file below, the important piece is that it is co-located with the layout definition)
- There would optionally be an icon for the layout in the same directory.
- A file named page.yml (again the name is arbitrary for the developer, but this defines the layout as bartik__page - the first part being the theme name, the second being the layout name, and the template file being looked for is derived from the .yml) would be located in the same directory. Example file contents:
title: Bartik page
sidebar_first: 'Sidebar first'
sidebar_second: 'Sidebar second'
triptych_first: 'Triptych first'
triptych_middle: 'Triptych middle'
triptych_last: 'Triptych last'
footer_firstcolumn: 'Footer first column'
footer_secondcolumn: 'Footer second column'
footer_thirdcolumn: 'Footer third column'
footer_fourthcolumn: 'Footer fourth column'
This file defines the layout, its name, regions, etc. The region definition in theme .info files becomes obsolete.
The same changes in a graphical way:
Which lets us make modules and install profiles even provide layouts either as static pre-built layouts (using the same file structure as themes) or dynamic layouts by implementing the plugin interface provided by the layout system. The patch includes a couple static layouts for demonstration as well.
|#144||layout-144.patch||21.64 KB||Gábor Hojtsy|
PASSED: [[SimpleTest]]: [MySQL] 42,380 pass(es).
|#141||layout-141.patch||25.8 KB||Gábor Hojtsy|
PASSED: [[SimpleTest]]: [MySQL] 42,375 pass(es).
|#132||interdiff.txt||5.51 KB||Gábor Hojtsy|
|#132||layout-132.patch||25.76 KB||Gábor Hojtsy|
PASSED: [[SimpleTest]]: [MySQL] 42,241 pass(es).
|#113||layout-113.patch||25.97 KB||Gábor Hojtsy|
PASSED: [[SimpleTest]]: [MySQL] 42,190 pass(es).