Created
February 27, 2016 17:54
-
-
Save 58bits/66968149924f80731c53 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/************************************************************* | |
* Prepares variables for the html.html.twig template. | |
* @param $variables | |
*/ | |
function basic_preprocess_html(&$variables) { | |
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; | |
} | |
if(!$variables['is_front']) { | |
$variables['attributes']['class'][] = 'with-subnav'; | |
} | |
// Add information about the number of sidebars. | |
if (!empty($variables['page']['sidebar_first']) && !empty($variables['page']['sidebar_second'])) { | |
$variables['attributes']['class'][] = 'two-sidebars'; | |
} | |
elseif (!empty($variables['page']['sidebar_first'])) { | |
$variables['attributes']['class'][] = 'one-sidebar'; | |
$variables['attributes']['class'][] = 'sidebar-first'; | |
} | |
elseif (!empty($variables['page']['sidebar_second'])) { | |
$variables['attributes']['class'][] = 'one-sidebar'; | |
$variables['attributes']['class'][] = 'sidebar-second'; | |
} | |
else { | |
$variables['attributes']['class'][] = 'no-sidebar'; | |
} | |
if (!empty($variables['page']['featured_top'])) { | |
$variables['attributes']['class'][] = 'has-featured-top'; | |
} | |
// If we're not on the front page. | |
if (!$variables['is_front']) { | |
// Add unique classes for each page and website section. | |
$path = \Drupal::service('path.current')->getPath(); | |
$alias = \Drupal::service('path.alias_manager')->getAliasByPath($path); | |
$alias = trim($alias, '/'); | |
$alias = str_replace('/', '-', $alias); | |
if (!empty($alias)) { | |
$variables['attributes']['class'][] = 'page-' . $alias; | |
list($section,) = explode('/', $alias, 2); | |
if (!empty($section)) { | |
$variables['attributes']['class'][] = 'section-' . $section; | |
} | |
} | |
} | |
// Add cachability metadata. | |
$theme_name = \Drupal::theme()->getActiveTheme()->getName(); | |
$theme_settings = \Drupal::config($theme_name . '.settings'); | |
CacheableMetadata::createFromRenderArray($variables) | |
->addCacheableDependency($theme_settings) | |
->applyTo($variables); | |
// Union all theme setting variables to the html.html.twig template. | |
$variables += $theme_settings->getOriginal(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{# | |
/** | |
* @file | |
* Default theme implementation for the basic structure of a single Drupal page. | |
* | |
* Variables: | |
* - logged_in: A flag indicating if user is logged in. | |
* - root_path: The root path of the current page (e.g., node, admin, user). | |
* - node_type: The content type for the current node, if the page is a node. | |
* - css: A list of CSS files for the current page. | |
* - head: Markup for the HEAD element (including meta tags, keyword tags, and | |
* so on). | |
* - head_title: A modified version of the page title, for use in the TITLE tag. | |
* - head_title_array: List of text elements that make up the head_title | |
* variable. May contain or more of the following: | |
* - title: The title of the page. | |
* - name: The name of the site. | |
* - slogan: The slogan of the site. | |
* - page_top: Initial rendered markup. This should be printed before 'page'. | |
* - page: The rendered page markup. | |
* - page_bottom: Closing rendered markup. This variable should be printed after | |
* 'page'. | |
* - styles: Style tags necessary to import all necessary CSS files in the head. | |
* - scripts: Script tags necessary to load the JavaScript files and settings | |
* in the head. | |
* - db_offline: A flag indicating if the database is offline. | |
* | |
* @see template_preprocess_html() | |
* | |
* @ingroup themeable | |
*/ | |
#} | |
{% set classes = [] %} | |
{% for role in user.roles %} | |
{% set classes = classes|merge(['role--' ~ role|clean_class]) %} | |
{% endfor %} | |
<!DOCTYPE html> | |
{% if ie_enabled_versions.ie8 %} | |
{{- attach_library('basic/ie8') }} | |
{% endif %} | |
{% if ie_enabled_versions.ie9 or ie_enabled_versions.ie8 %} | |
<!--[if lt IE 7]> <html{{ html_attributes.addClass('no-js', 'lt-ie9', 'lt-ie8', 'lt-ie7') }}><![endif]--> | |
<!--[if IE 7]> <html{{ html_attributes.removeClass('lt-ie7') }}><![endif]--> | |
<!--[if IE 8]> <html{{ html_attributes.removeClass('lt-ie8') }}><![endif]--> | |
<!--[if gt IE 8]><!--><html{{ html_attributes.removeClass('lt-ie9') }}><!--<![endif]--> | |
{% else -%} | |
<html{{ html_attributes }}> | |
{% endif %} | |
<head> | |
<head-placeholder token="{{ placeholder_token }}"> | |
<title>{{ head_title|safe_join(' | ') }}</title> | |
<css-placeholder token="{{ placeholder_token }}"> | |
<js-placeholder token="{{ placeholder_token }}"> | |
</head> | |
<body{{ attributes.addClass(classes) }}> | |
<div id="skip"> | |
<a href="#main-menu" class="visually-hidden focusable skip-link"> | |
{{ 'Skip to main navigation'|t }} | |
</a> | |
</div> | |
{{ page_top }} | |
{{ page }} | |
{{ page_bottom }} | |
<js-bottom-placeholder token="{{ placeholder_token }}"> | |
{% if browser_sync.enabled %} | |
<script id="__bs_script__"> | |
document.write("<script async src='http://{{ browser_sync.host }}:{{ browser_sync.port }}/browser-sync/browser-sync-client.js'><\/script>".replace("HOST", location.hostname)); | |
</script> | |
{% endif %} | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment