Programatically render block with contextual links (in php) I'm trying to find a solution to embed a drupal custom block using PHP. I found this snippet that works : 

&lt;?php
$block = \Drupal\block\Entity\Block::load('your_block_id');
$render = \Drupal::entityTypeManager()-&gt;getViewBuilder('block')-&gt;view($block);
print render($render);
?&gt;


The problem is that this code directly render the block content, I don't have any contextual links for that block. My question is, how to render the whole block (including contextual links), exactly like if I added it in a region using the UI.

Thank you
You can use the Twig Tweak module to insert the 'local tasks' menu in your template file: 

{{ drupal_entity('block', 'THEME_local_tasks', check_access=true) }}