如何在'hook_preprocess_block'中获取当前区域id?

时间:2017-07-14 14:24:19

标签: drupal hook block preprocessor theming

如何在hook_preprocess_block()内获取当前地区ID? 我尝试了以下代码,但似乎有些不对劲。

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

1 个答案:

答案 0 :(得分:1)

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