Change the site slogan on certain pages
Ok, thanks to the hint from @Hudri, here's what I did.

In mycustomtheme.theme:

function MYCUSTOMTHEME_preprocess_block(&amp;$vars) {
  if ($vars['configuration']['id'] === 'MYMODULE_site_branding_nolinks_block') {
    $site_config = \Drupal::config('system.site');
    $vars['site_slogan'] = $site_config-&gt;get('slogan');
    $vars['site_name'] = $site_config-&gt;get('name');
    $node = \Drupal::routeMatch()-&gt;getParameter('node');
    if ($node instanceof \Drupal\node\NodeInterface) {
      $type = $node-&gt;getType();
      // For landing pages, set the site slogan to the value of the slogan field.
      if ($type === 'landingpage') {
        $node = \Drupal::entityTypeManager()-&gt;getStorage('node')-&gt;load($node-&gt;id());
        $slogan_field = $node-&gt;get('field_slogan')-&gt;getValue();
        $slogan_field = $slogan_field[0]['value'];
        $vars['site_slogan'] = $slogan_field;
      }
    }
  }
}


But, we're not done yet, because the block (provided by my custom module) is cached the same for every page; it needs to be cached per URL, since it might be different for each landing page.

To fix that, in mymodule/src/Plugins/Blocks/myBlock.php, add this code:

  // Caching must be added here:
  // https://drupal.stackexchange.com/questions/223376/what-is-the-correct-way-to-set-cache-contexts-on-custom-blocks
  public function getCacheContexts() {
    return Cache::mergeContexts(parent::getCacheContexts(), ['url.path', 'url.query_args']);
  }