title: How to execute a Drupal-view in a custom module and print the output (as html-markup)?
body: <p>I want to print the output from a simple view in my custom module. But is doesnt work. I have tried many options from forums and stackoverflow. All of them print "array" instead of html-markup. </p>
  
  <p>My controller:</p>
  
  <pre><code>class DefaultController extends ControllerBase {
  
  
      public function myfunc1() {
  
          $view = Views::getView('myfirstview');
  
          $view-&gt;setDisplay('page_1');
          $view-&gt;preExecute();
          $view-&gt;execute();
  
          // $myresults = $view-&gt;preview();  = array
          // $myresults = $view-&gt;render();  = array
          $myresults = $view-&gt;result; // = array
  
  
          return array(
              '#title' =&gt; 'Hello World!',
              '#markup' =&gt; $myresults,
          );
      }
  }
  </code></pre>
  
  <p>How can I print the result/output of a view programmatically? </p>
  
  <p>I dont want to make it without "embed view" , because I want to set some exposed filters later. </p>