Drupal 7 rendering. Roles and responsibilities
I have lots to say about the awesome new page rendering in Drupal 7. For now, I want to clarify the design. The meaning of some familiar features has changed:
- Regions. Regions are promises made by a theme: “I will print whatever you put into these part of the $page array.”
- Hook_block(). A modules uses this to make pre-packaged hunks of content available to the CMS
- Block module. An optional UI where admin populates regions with blocks
- $page array. See graphic below. $page gets built up during a page request. At the top level of the array we find each region. Within each region we find renderable arrays that often correspond to blocks. After page building is complete, core calls drupal_render($page). We theme each element of the array until we finally get to page.tpl.php
- Hook_page_alter(). A chance for the site builder to change almost anything about the $page before it is rendered. Populating regions is perfectly reasonable here (e.g. toolbar module). Thats what block.module does.
- Preprocess layer. A useful place to make minor tweaks to variables before they are printed in templates. Core should not call drupal_render() here. Core should strive to remove all drupal_render() calls from Drupal except drupal_render_page() and render() in templates (e.g. node.tpl.php).
Here is the $page array from current HEAD: