8 theme.inc template_preprocess_page(&$variables)
6 theme.inc template_preprocess_page(&$variables)
7 theme.inc template_preprocess_page(&$variables)

Prepares variables for the page template.

Default template: page.html.twig.

Most themes use their own copy of page.html.twig. The default is located inside "modules/system/page.html.twig". Look in there for the full 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 1320
The theme system, which controls the output of Drupal.

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] = array();
    }
  }

  $variables['base_path'] = base_path();
  $variables['front_page'] = \Drupal::url('<front>');
  $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')) {
    $variables['node'] = $node;
  }
}

Comments

My template_preprocess_page() implementation to get theme path in page.html.twig:

<?php
/**
 * Implements template_preprocess_page().
 */
function THEME_preprocess_page(&$variables) {
 
$theme = \Drupal::theme()->getActiveTheme()->getName();
 
$variables['theme_path'] = drupal_get_path('theme', $theme);
}
?>

...and in my page.html.twig file:

<img src="/{{ theme_path }}/images/image.jpg" class="img-responsive" alt=""/>