0

I would like to display a multi value media field and its file type and size in a content type and display it in a table layout. I thought using a view would be the best way to pull the media file type and file size and any references it has using views relations.

The view uses Relations to get the media type and size and uses a Contextual filter - Content ID from URL. Now I am printing the display in a node template like this using Twig tweak.

{{ drupal_view('materials', 'block_1') }}

The table and media values display fine when published on route entity.node.canonical.

But the media values do not display on other routes and tabs like /latest routename entity.node.latest_version and /full routename entity.node.preview. The table markup displays but not the media values inside. I have tried printing the view using the drupal_block method and had the same results.

1 Answer 1

0

The content id is missing from your function call you have to add it like this

{{ drupal_view('who_s_new', 'block_1', arg_1, arg_2, arg_3) }}

or you can render your view in custom block and add it in every page via 'block layout'

https://www.webwash.net/programmatically-create-block-drupal-8/

$view = views_get_view('view_name');
$view->set_display('view_block_name');
$view->set_arguments(array($tid));
// change the amount of items to show
$view->set_items_per_page(4);
$view->pre_execute();
$view->execute();
$view->render();

Your Answer

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

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