I have region--footer-sustain.html.twig which is expressed in templates via {{page['footer_sustain']}}.
Client wants some content moved into the CMS so I added to theme_info.yml these regions:
sustain_footer_left : 'Sustain Footer Left Col' sustain_footer_middle : 'Sustain Footer Middle Col' sustain_footer_right : 'Sustain Footer Right Col'
I added the HTML to new Custom Blocks and assigned the blocks to the regions in the same way I have all over the site but no output was expressed.
I tried {{page['sustain_footer_left']}} and spitballing tried {{region['sustain_footer_middle']}} and later {{sustain_footer_right}}
After reading Place block region in node template I tried editing theme.theme with the following:
function theme_add_regions_to_node($allowed_regions, &$variables) { // Retrieve active theme $theme = \Drupal::theme()->getActiveTheme()->getName(); // Retrieve theme regions $available_regions = system_region_list($theme, 'REGIONS_ALL'); // Validate allowed regions with available regions $regions = array_intersect(array_keys($available_regions), $allowed_regions); // For each region foreach ($regions as $key => $region) { // Load region blocks $blocks = entity_load_multiple_by_properties('block', array('theme' => $theme, 'region' => $region)); // Sort ‘em uasort($blocks, 'Drupal\block\Entity\Block::sort'); // Capture viewable blocks and their settings to $build $build = array(); foreach ($blocks as $key => $block) { if ($block->access('view')) { $build[$key] = entity_view($block, 'block'); } } // Add build to region $variables[$region] = $build; } } And then called it like so:
function theme_preprocess_node(&$variables) { $view_mode = $variables['view_mode']; // Retrieve view mode $allowed_view_modes = array('full'); // Array of allowed view modes (for performance so as to not execute on unneeded nodes) // If view mode is in allowed view modes list, pass to THEME_add_regions_to_node() if(in_array($view_mode, $allowed_view_modes)) { // Allowed regions (for performance so as to not execute for unneeded region) $allowed_regions = array('sustain_footer_left','sustain_footer_middle','sustain_footer_right'); theme_add_regions_to_node($allowed_regions, $variables); } } Also tried commenting out the if(in_array()) as a test. Also tried doing same in theme_preprocess_page().
UPDATE
Also tried
$variables['sustain_footer_right'] = entity_load('block_content', 'sustainfooterrightcolumn')->getPlugin()->build(); $block = \Drupal\block_content\Entity\BlockContent::load('sustainfooterrightcolumn'); // $variables['sustain_footer_right'] = \Drupal::entityTypeManager()->getViewBuilder('block_content')->view($block); And also tried
$custom_block = \Drupal::entityTypeManager()->getStorage('block_content')->load('96'); $variables['sustain_footer_right'] = $custom_block->field_myfield->value; AND ALSO TRIED
$block = \Drupal\block\Entity\Block::load('sustainfooterrightcolumn'); if ($block) { $variables['sustain_footer_right'] = \Drupal::entityManager() ->getViewBuilder('block') ->view($block); } else { $variables['sustain_footer_right'] = 'x'; } Also in twig tried all of these, and yes, cleared cache every time.
{{sustain_footer_right}} {{page.sustain_footer_right}} {{page['sustain_footer_right']}}
I get no errors but also no output. How do I get the content of these blocks to be expressed in region--footer-sustain.html.twig ?