Search code examples
drupalhookblockpreprocessortheming

How can I get the current region id inside the 'hook_preprocess_block'?


How can I get the current region ID inside hook_preprocess_block()?
I tried the following code, but it seems something is wrong.

function ThemeName_preprocess_block(&$variables) {
  if ($variables['elements']['#region'] == "nav") {
    $variables['attributes']['class'][] = 'SomeStyle';
  }
}

Solution

  • $region = $variables['elements']['#configuration']['region'];