function template_preprocess_page
Same name in other branches
- 7.x includes/theme.inc \template_preprocess_page()
- 9 core/includes/theme.inc \template_preprocess_page()
- 8.9.x core/includes/theme.inc \template_preprocess_page()
- 11.x core/includes/theme.inc \template_preprocess_page()
Prepares variables for the page template.
Default template: page.html.twig.
See the page.html.twig template for the list of variables.
1 call to template_preprocess_page()
- template_preprocess_maintenance_page in core/
includes/ theme.inc - Prepares variables for maintenance page templates.
File
-
core/
includes/ theme.inc, line 1367
Code
function template_preprocess_page(&$variables) {
$language_interface = \Drupal::languageManager()->getCurrentLanguage();
foreach (\Drupal::theme()->getActiveTheme()
->getRegions() as $region) {
if (!isset($variables['page'][$region])) {
$variables['page'][$region] = [];
}
}
$variables['base_path'] = base_path();
$variables['front_page'] = Url::fromRoute('<front>')->toString();
$variables['language'] = $language_interface;
// An exception might be thrown.
try {
$variables['is_front'] = \Drupal::service('path.matcher')->isFrontPage();
} catch (Exception $e) {
// If the database is not yet available, set default values for these
// variables.
$variables['is_front'] = FALSE;
$variables['db_is_active'] = FALSE;
}
if (($node = \Drupal::routeMatch()->getParameter('node')) || ($node = \Drupal::routeMatch()->getParameter('node_preview'))) {
$variables['node'] = $node;
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.