I have created a custom block though Drupal Admin mentioning page restrictions (to show only on listed pages) and have included this block programmatically in a node twig file but, this block shows up in all the node pages rather than only mentioned pages. How to restrict this block to display only on restricted pages through coding?
I have already restricted the pages in block (created through Admin interface) but the block is being displayed irrespective of it's page restriction on all node pages.
// Code in .theme file, which works irrespective of pages mentioned in configuration settings for "show only on listed pages":
function my_sitedesigntheme_theme_preprocess_node(&$variables) {
$block = Drupal\block_content\Entity\BlockContent::load(31);
$variables['my_block_data'] = \Drupal::entityTypeManager()->getViewBuilder('block_content')->view($block);
}
// Code in twig file:
{{ my_block_data }}
The block should be displayed (which is already being displayed) but only on listed pages in custom block config settings.