I want to render two views in the same twig template, but only one of them is rendered, and the second is always override with the same content as the first one.
I have a content type 'contacts' and when its nodes are displayed (full view) I want to render two views in the same page after the node fields. I use a twig template node--contacts.html.twig :
..... node fields twig template ....
{{ viewCalls }}
....
{{ viewAppointments }}
....
And my function my_theme_preprocess_node(&$variables)
in my .theme file:
....
$view = \Drupal\views\Views::getView('view_calls');
$view->setDisplay('default');
$view->setArguments(array($variables['node']->id()));
$view->setOffset(0);
$view->execute();
$variables['viewCalls'] = $view->render();
$view2 = \Drupal\views\Views::getView('view_appointments');
$view2->setDisplay('default');
$view2->setArguments(array($variables['node']->id()));
$view2->setOffset(0);
$view2->execute();
$variables['viewAppointments'] = $view2->render();
.....
As I said, the second view always shows the same content as the first. If I reverse the order of rendering, then the content is reverse too, and the one which is first rendered is the only one I see, and always two times. It is as {{ viewCalls }}
and {{ viewAppointments }}
always get the same content.