How do I set a specific image header for each page?
After some many headache...
I believe I got what I wanted, thanks to Ivan.


  SubheaderBlock.php


&lt;?php
/**
 * Provides a 'Subheader' Block
 *
 * @Block(
 *   id = "slssubheader",
 *   admin_label = @Translation("slssubheader"),
 * )
 */

namespace Drupal\subheader\Plugin\Block;
use Drupal\Core\Block\BlockBase;

class SubheaderBlock extends BlockBase {
  /**
   * {@inheritdoc}
   */
  public function build() {

   // get the node id if exist
   $node = \Drupal::routeMatch()-&gt;getParameter('node');
   $nid = $node ? $node-&gt;id() : 0 ;


   $outpout['id'] = array(
           '#markup' =&gt; $nid,
           '#cache'=&gt;[
                 'contexts' =&gt; ['url:pager_id' ],
                 ]

       );

    return $outpout;
  }
}
?&gt;


I get the id in twig with

{{ content.id }}


I checked with a a random number rand(1,100) it works perfect. There is one different cache per nid.

althought it works, I am not sure about the best practice for #markup and url:pager_id