Skip to main content
Bounty Ended with 50 reputation awarded by CommunityBot
added 85 characters in body
Source Link
leymannx
  • 18.8k
  • 6
  • 72
  • 126

Got it!

You have to pass the view ID and the display ID to drupal_view() dynamically.

But first let me tell you that what you are doing, printing node stuff inside page level templates, should be considered bad practice. Good practice is to leave templates untouched, and to offer field formatters and other stuff instead that keeps the admin UI intact. So, when you get your first maintenance breakdown in a year or so, don't tell us we didn't warn you.

page.html.twig

{% if node.field_views and not node.field_views.isEmpty() %}
  {% for view in node.field_views.value %}
    {{ drupal_view(view['target_id'], view['display_id']) }}
  {% endfor %}
{% endif %}

You won't get the view title from here. Simply add some Global: unfiltered text to your view HEADER with any title markup. That will get printed.


drupal_view() requires Twig Tweak.

Got it!

But first let me tell you that what you are doing, printing node stuff inside page level templates, should be considered bad practice. Good practice is to leave templates untouched, and to offer field formatters and other stuff instead that keeps the admin UI intact. So, when you get your first maintenance breakdown in a year or so, don't tell us we didn't warn you.

page.html.twig

{% if node.field_views and not node.field_views.isEmpty() %}
  {% for view in node.field_views.value %}
    {{ drupal_view(view['target_id'], view['display_id']) }}
  {% endfor %}
{% endif %}

You won't get the view title from here. Simply add some Global: unfiltered text to your view HEADER with any title markup. That will get printed.


drupal_view() requires Twig Tweak.

Got it!

You have to pass the view ID and the display ID to drupal_view() dynamically.

But first let me tell you that what you are doing, printing node stuff inside page level templates, should be considered bad practice. Good practice is to leave templates untouched, and to offer field formatters and other stuff instead that keeps the admin UI intact. So, when you get your first maintenance breakdown in a year or so, don't tell us we didn't warn you.

page.html.twig

{% if node.field_views and not node.field_views.isEmpty() %}
  {% for view in node.field_views.value %}
    {{ drupal_view(view['target_id'], view['display_id']) }}
  {% endfor %}
{% endif %}

You won't get the view title from here. Simply add some Global: unfiltered text to your view HEADER with any title markup. That will get printed.


drupal_view() requires Twig Tweak.

Source Link
leymannx
  • 18.8k
  • 6
  • 72
  • 126

Got it!

But first let me tell you that what you are doing, printing node stuff inside page level templates, should be considered bad practice. Good practice is to leave templates untouched, and to offer field formatters and other stuff instead that keeps the admin UI intact. So, when you get your first maintenance breakdown in a year or so, don't tell us we didn't warn you.

page.html.twig

{% if node.field_views and not node.field_views.isEmpty() %}
  {% for view in node.field_views.value %}
    {{ drupal_view(view['target_id'], view['display_id']) }}
  {% endfor %}
{% endif %}

You won't get the view title from here. Simply add some Global: unfiltered text to your view HEADER with any title markup. That will get printed.


drupal_view() requires Twig Tweak.