I have a view that calls for Show: Content, using a very specific view mode (neither Full content nor Teaser, it's created on purpose and themed according to my needs, basically an e-mail oriented output with very different HTML classes than the usual views displays in Drupal). When used in a page, it renders perfectly. However, when I render it from code to be able to use the resulting HTML directly:
$view = Views::getView('view_id');
$view->setDisplay('default');
$view->setArguments($args);
$view->preExecute();
$view->execute();
$render = $view->render();
$html = render($render);
I get an otherwise perfect render but not with that view mode, just the usual stuff. Alternative calls do the same:
$render = $view->buildRenderable('default', $args);
$html = render($render);
How could I force it to render the way I want it?
default
above when it should be another value, whatever your display's machine name is (it's in the Advanced column under Other).default
intentionally. These are internal use views that are never rendered normally, neither page nor block, they are only rendered into controllers where they need to appear. But I figured out the reason, I'll add an answer now.