1

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?

3
  • which view mode are you trying to display? which view display id are you trying to display?
    – sonfd
    Commented Jun 2, 2018 at 1:50
  • 1
    I'm pretty sure you are using default above when it should be another value, whatever your display's machine name is (it's in the Advanced column under Other).
    – sonfd
    Commented Jun 2, 2018 at 1:57
  • It's 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.
    – Gábor
    Commented Jun 2, 2018 at 10:11

1 Answer 1

1

It was the theme. The rendering took place under cron and ran under the administration theme rather than the usual one, meaning different twigs. The solution will be to sub-theme the admin theme to make sure all the relevant twigs are present there, too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.