function uikit_preprocess_page

8.x-3.x preprocess.inc uikit_preprocess_page(&$variables)
8.x-2.x preprocess.inc uikit_preprocess_page(&$variables)
7.x-3.x preprocess.inc uikit_preprocess_page(&$variables)
7.x-2.x preprocess.inc uikit_preprocess_page(&$variables)

Implements template_preprocess_page().

File

includes/preprocess.inc, line 23
Set up variables to be placed within the template (.html.twig) files.

Code

function uikit_preprocess_page(&$variables) {
  // Assign new header attributes.
  $variables ['header_attributes'] = new Attribute();
  $variables ['header_attributes']['id'] = 'page--header';
  $variables ['header_attributes']['class'] = [];

  // Assign new navbar attributes.
  $variables ['navbar_attributes'] = new Attribute();
  $variables ['navbar_attributes']->setAttribute('id', 'page--navbar');
  $variables ['navbar_attributes']->addClass('uk-navbar-container');
  $variables ['navbar_attributes']->setAttribute('uk-navbar', '');

  // Assign new page attributes.
  $variables ['page_attributes'] = new Attribute();
  $variables ['page_attributes']['id'] = 'page';
  $variables ['page_attributes']['class'] = [];

  // Add classes to page attribtues based on theme settings.
  $page_container = UIkit::getThemeSetting('page_container');
  if ($page_container) {
    $variables ['page_attributes']['class'][] = 'uk-container';
  }
  $page_margin = UIkit::getThemeSetting('page_margin');
  if ($page_margin) {
    $variables ['page_attributes']['class'][] = $page_margin;
  }

  // Get the grid classes for the page content and sidebars.
  $left_sidebar = !empty($variables ['page']['sidebar_first']);
  $right_sidebar = !empty($variables ['page']['sidebar_second']);
  $grid_classes = UIkit::getGridClasses($left_sidebar, $right_sidebar);

  // Add page content grid classes.
  $variables ['content_attributes']['id'] = 'page--content';
  foreach ($grid_classes ['content'] as $content_class) {
    $variables ['content_attributes']['class'][] = $content_class;
  }

  if ($left_sidebar) {
    // Add left sidebar grid classes.
    $variables ['sidebar_first_attributes'] = new Attribute();
    $variables ['sidebar_first_attributes']['id'] = 'page--sidebar-first';
    $variables ['sidebar_first_attributes']['class'] = [];
    foreach ($grid_classes ['sidebar']['first'] as $sidebar_first_class) {
      $variables ['sidebar_first_attributes']['class'][] = $sidebar_first_class;
    }
  }
  if ($right_sidebar) {
    // Add right sidebar grid classes.
    $variables ['sidebar_second_attributes'] = new Attribute();
    $variables ['sidebar_second_attributes']['id'] = 'page--sidebar-second';
    $variables ['sidebar_second_attributes']['class'] = [];
    foreach ($grid_classes ['sidebar']['second'] as $sidebar_second_class) {
      $variables ['sidebar_second_attributes']['class'][] = $sidebar_second_class;
    }
  }
}

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.

Log in