Passing variables to custom block I am trying to pass variables to a custom block in a module. I can see that the custom block is used in the code, however I cannot get the variables to show up.

Any help much appreciated:

I am themeing the block in the module file

function etypeservices_theme($existing, $type, $theme, $path) {
   return [
    'block__etypeservices' =&gt; [
      'variables' =&gt; [
        'facebook' =&gt; '',
     ],
   ],
];
}


I am building the render array

class SocialBlock extends BlockBase implements BlockPluginInterface {
/**
 * {@inheritdoc}
 */
public function build() {
    $config = \Drupal::config('etypeservices.settings');
    $facebook = $config-&gt;get('facebook');
    return [
      '#theme' =&gt; 'block__etypeservices',
      '#facebook' =&gt; $facebook,
   ];
 }


}


and here is the template

{%
    set classes = [
   'block',
   'block-social-icons',
   ]
%}
&lt;div{{ attributes.addClass(classes) }}&gt;
   &lt;ul class="list-style-none"&gt;
    {% if facebook %}
    &lt;li&gt;&lt;a href="https://www.facebook.com/{{ facebook }}" target="_blank"&gt;Facebook&lt;/a&gt;&lt;/li&gt;
    {% endif %}
   &lt;/ul&gt;
&lt;/div&gt;


Can anybody see why this is not working?
For a custom template use your own theme hook etypeservices:

function etypeservices_theme($existing, $type, $theme, $path) {
   return [
    'etypeservices' =&gt; [
      'variables' =&gt; [
        'facebook' =&gt; '',
     ],
   ],
];
}


Which uses it's own variables space:

public function build() {
    $config = \Drupal::config('etypeservices.settings');
    $facebook = $config-&gt;get('facebook');
    return [
      '#theme' =&gt; 'etypeservices',
      '#facebook' =&gt; $facebook,
   ];
 }
}


etypeservices.html.twig

{{ facebook }}


The content of the block is a normal render array, which can contain one or more custom templates to make them accessible in theming. These custom templates are reusable, not only in blocks.

In a module you can override the block template, as you tried to do by using block__..., but you need this in very rare cases. In drupal core there is only one. Then you will inherit the variables of the base hook block. 

But normally you leave the block template as it is, so that it can be themed on it's own.