1.20.x theme.inc template_preprocess_page(&$variables)

Preprocess variables for page.tpl.php

See also

system_elements()

page.tpl.php

File

includes/theme.inc, line 2724
The theme system, which controls the output of Backdrop.

Code

function template_preprocess_page(&$variables) {
  // Compile a list of classes that are going to be applied to the body element.
  // This allows for easy CSS overrides based on context (home page, node of
  // certain type, etc.).

  // Add a class that tells us whether we're on the home page or not.
  if ($variables['is_front']) {
    $variables['classes'][] = 'front';
  }

  // Add a class that tells us whether the page is viewed by an authenticated user or not.
  if ($variables['logged_in']) {
    $variables['classes'][] = 'logged-in';
  }

  // If on an individual node page, add the node type to body classes.
  if ($node = menu_get_object()) {
    $variables['classes'][] = backdrop_html_class('node-type-' . $node->type);
  }

  // Initialize attributes which are specific to the html and body elements.
  $variables['html_attributes'] = array();
  $variables['html_attributes']['lang'] = $GLOBALS['language']->langcode;
  $variables['html_attributes']['dir'] = $GLOBALS['language']->direction ? 'rtl' : 'ltr';
  $variables['body_attributes'] = array();

  // Add favicon.
  $favicon = backdrop_get_favicon();
  backdrop_add_html_head_link(array('rel' => 'shortcut icon', 'href' => $favicon['path'], 'type' => $favicon['type']));

  $site_config = config('system.core');
  // Construct head <title>.
  if (backdrop_get_title()) {
    $head_title = array(
      'title' => strip_tags(backdrop_get_title()),
      'name' => check_plain($site_config->getTranslated('site_name')),
    );
  }
  else {
    $head_title = array('name' => check_plain($site_config->getTranslated('site_name')));
    if ($slogan = $site_config->getTranslated('site_slogan')) {
      $head_title['slogan'] = check_plain($slogan);
    }
  }
  $variables['head_title_array'] = $head_title;
  $variables['head_title'] = implode(' | ', $head_title);
}