I need to re-use the same menu in two different regions, with slightly different markup. My thought was to simply check which region the block was being rendered in, and use if statements to modify the classes/structure as needed.
I've hit a roadblock; I was able to find a way to get what region a block is in, but I can't figure out how to pass that data to the menu. Here's my current code:
// Add a region variable to a block.
function theme_preprocess_block(&$variables, $hook) {
$block_id = $variables["elements"]["#id"];
$block = \Drupal\block\Entity\Block::load($block_id);
$variables["region"] = $block->getRegion();
}
I can output the region
variable just fine in block--system-menu-block.html.twig
, but trying the variable doesn't get passed to menu.html.twig
, which is where I need it.
I feel like I'm a stones through form an answer for this, if someone could point me in the right direction I'd be greatly appreciative.
Quick side note: I'm very new to Drupal, coming from WordPress development. So far it's been a difficult transition, so please assume I know nothing about themeing :)