Skip to content

Instantly share code, notes, and snippets.

@waako
Last active August 31, 2016 20:30
Show Gist options
  • Save waako/374689bdd10f133dbec7033e56ce8266 to your computer and use it in GitHub Desktop.
Save waako/374689bdd10f133dbec7033e56ce8266 to your computer and use it in GitHub Desktop.
Get value of field from a node inside region
<?php
/**
* Implements hook_preprocess_HOOK() for region templates.
*/
function themename_preprocess_region__region_name(&$variables) {
// Check if current page is a node.
if ($node = \Drupal::routeMatch()->getParameter('node')) {
// Check if node has the field site_section.
if ($node->hasField('field_site_section')) {
$variables['site_section'] = $node->get('field_site_section')->value;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment