I've followed some previous solutions on DA to programmatically load a Custom block in my page preprocessor hook but nothing I try seems to be working.
Currently, my custom block is within Structure > Block Layout > Custom block Library under the name 'SGT Pricing Header' (Machine name: sgt_pricing_header
, ID 12).
I have attempted loading it in the page preprocessor as well as the node preprocessor hooks.
Currently I have:
function THEME_preprocess_node(&$variables) {
$block_entity = Drupal\block_content\Entity\BlockContent::load(12);// BLOCK_ID
$block_view = \Drupal::entityTypeManager()->getViewBuilder('block_content')->view($block_entity, 'sgt_pricing_header');
$variables['block_pricing_header'] = $block_view;
}
I have also used 'sgt_pricing_header' in place of the ID 2 with no success.
In the TWIG template, which is a paragraph template by the way, if that is relevant, I am simply trying to display the block with
{{ block_pricing_header }}
I referenced Programatically render a block in a twig template when trying to get this to work.
I also tried using Twig Tweak to display the block, without success.
{{ drupal_block('sgt_pricing_header') }}
Simply does nothing.
PHP Version: 5.6.32-1+ubuntu17.10.1+deb.sury.org+1 Drupal version: Lightning (lightning-8.x-2.17)
Not entirely certain what to try next other than simply hard code the block content into the template which I would prefer to avoid.