function hook_page_alter

×

Error message

User warning: The following module is missing from the file system: theme/theme. For information about how to fix this, see the documentation page. in _drupal_trigger_error_with_delayed_logging() (line 1156 of /var/www/html/elmsln_community/api.elmsln.org/includes/bootstrap.inc).
cis7 system.api.php hook_page_alter(&$page)
cle7 system.api.php hook_page_alter(&$page)
elmsmedia7 system.api.php hook_page_alter(&$page)
icor7 system.api.php hook_page_alter(&$page)
meedjum_blog7 system.api.php hook_page_alter(&$page)
mooc7 system.api.php hook_page_alter(&$page)

Perform alterations before a page is rendered.

Use this hook when you want to remove or alter elements at the page level, or add elements at the page level that depend on an other module's elements (this hook runs after hook_page_build().

If you are making changes to entities such as forms, menus, or user profiles, use those objects' native alter hooks instead (hook_form_alter(), for example).

The $page array contains top level elements for each block region:

  $page['page_top']
  $page['header']
  $page['sidebar_first']
  $page['content']
  $page['sidebar_second']
  $page['page_bottom']

The 'content' element contains the main content of the current page, and its structure will vary depending on what module is responsible for building the page. Some legacy modules may not return structured content at all: their pre-rendered markup will be located in $page['content']['main']['#markup'].

Pages built by Drupal's core Node and Blog modules use a standard structure:

  // Node body.
  $page['content']['system_main']['nodes'][$nid]['body']
  // Array of links attached to the node (add comments, read more).
  $page['content']['system_main']['nodes'][$nid]['links']
  // The node object itself.
  $page['content']['system_main']['nodes'][$nid]['#node']
  // The results pager.
  $page['content']['system_main']['pager']

Blocks may be referenced by their module/delta pair within a region:

  // The login block in the first sidebar region.
  $page['sidebar_first']['user_login']['#block'];

Parameters

$page: Nested array of renderable elements that make up the page.

See also

hook_page_build()

drupal_render_page()

Related topics

20 functions implement hook_page_alter()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

adaptivetheme_page_alter in sites/all/themes/ulmus/adaptivetheme/at_core/inc/alter.inc
hook_page_alter()
alpha_page_alter in sites/all/themes/ulmus/omega/alpha/template.php
Implements hook_page_alter().
book_page_alter in modules/book/book.module
Implements hook_page_alter().
boxes_page_alter in sites/all/modules/ulmus/boxes/boxes.module
Implements hook_page_alter().
context_page_alter in sites/all/modules/ulmus/context/context.module
implement hook_page_alter()

... See full list

2 invocations of hook_page_alter()
drupal_render_page in includes/common.inc
Renders the page, including all theming.
wysiwyg_render_dialog_page in sites/all/modules/ulmus/wysiwyg/wysiwyg.dialog.inc

File

modules/system/system.api.php, line 1627
Hooks provided by Drupal core and the System module.

Code

function hook_page_alter(&$page) {
  // Add help text to the user login block.
  $page['sidebar_first']['user_login']['help'] = array(
    '#weight' => -10,
    '#markup' => t('To post comments or add new content, you first have to log in.'),
  );
}
Error | ELMSLN API

Error

×

Error message

  • Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/elmsln_community/api.elmsln.org/includes/common.inc:2791) in drupal_send_headers() (line 1499 of /var/www/html/elmsln_community/api.elmsln.org/includes/bootstrap.inc).
  • Error: Call to undefined function apc_delete() in DrupalAPCCache->clear() (line 289 of /var/www/html/elmsln_community/api.elmsln.org/sites/all/modules/apc/drupal_apc_cache.inc).
The website encountered an unexpected error. Please try again later.