How do call the template for a module block My goal is create a custom block that uses a twig template that you can pass info to via the theme function like so.

  public function build() {
    return array(
      '#type' =&gt; 'markup',
      '#markup' =&gt; $this-&gt;siteContent(),
    );
  }

  public function siteContent() {

    $source_text = some_function_returning_html_from_user();

    return array(
      '#theme' =&gt; 'scadfashblock',
      '#source_text' =&gt; $source_text,
    );
  }


I got the above code from a tutorial trying to render a template file for a custom page. The problem is this code throws an error saying that an array can't be returned this way, it must be a string. 

I even tried doing it the drupal 7 way...

  public function build() {
    return array(
      '#type' =&gt; 'markup',
      '#markup' =&gt; $this-&gt;siteContent(),
    );
  }

  private function siteContent() {

    $output = array();
    $output['source_text'] = some_function_returning_html_from_user();

    return theme('scadfashblock', $output);
  }


This throws an error:


  Call to undefined function Drupal\&lt;module&gt;\Plugin\Block\theme()
The markup render #type takes a string for its #markup element property, not a render array. However you do not need to wrap your custom theme/template with the markup type.

  public function build() {
    return array(
      '#theme' =&gt; 'scadfashblock',
      '#source_text' =&gt; $this-&gt;siteContent(),
    );
  }

  public function siteContent() {
    return some_function_returning_html_from_user();
  }


Then implement scadfashblock in hook_theme, provide a template_preprocess_scadfashblock and a templates/scadfashblock.html.twig with your markup.