Task type
Project
Parent task
Topics
Documentation
Modules
Changed
Context
Views attachments don't print their title. The main inventory dashboard is a view with 3 attachments.
Discovery
Attempting to use text in header area as a workaround works for attachments, but the main display header printed is above the attachments.
I could make the main display be the one at the top, and place attachments after it.
The previous view used a hack - add the display title as a field, then group by it.
This could be fixed by modifying templates, or a preprocess hook. What should the rule be?
View on Drupal.org #1619498 Views doesn't output $title for page Status: Closed (works as designed)
The display type and title can be added as variables to use in the template.
function mantra_starter_preprocess_views_view(&$variables) {
/* @var $view \Drupal\views\ViewExecutable */
$view = $variables['view'];
$variables['display_type'] = $view->getDisplay()->getPluginId();
$variables['display_title'] = $view->display_handler->display['display_title'];
}{{ title_prefix }}
{% if title %}
{{ title }}
{% endif %}
{% if display_type == 'attachment' %}
<h2>{{ display_title }}</h2>
{% endif %}
{{ title_suffix }}{% if attachment_before %}
<div class="attachment attachment-before">
{{ attachment_before }}
</div>
<h2>{{ display_title }}</h2>
{% endif %}Done
Used the attachment footer area to set the title for the display below it.