drupal 9 how to render a view block from render array with arguments
To render a view block from a render array with arguments in Drupal 9, you can use the following code:
$view = \Drupal::entityTypeManager()->getViewBuilder('view')->view('view_name', 'display_id', $arguments);
$render_array = \Drupal::entityTypeManager()->getViewBuilder('block')->view($view);
Replace 'view_name'
with the machine name of your view and 'display_id'
with the machine name of the display you want to render. The $arguments
variable should be an associative array that contains the arguments you want to pass to the view.
Once you have the $render_array
, you can render it using the render()
function:
$output = render($render_array);
This will give you the rendered output of the view block with the provided arguments.
Note that this code assumes you are working in a PHP file or in a custom module. Make sure to adjust the code accordingly based on your specific implementation.
Hope this helps!