Question

On a site we are working on I was asked why the page titles are wrapped with a span tag. We are not using a base theme.

I checked everywhere I could think of, but came up short.

In page-title.html.twig:

{#
/**
 * @file
 * Theme override for page titles.
 *
 * Available variables:
 * - title_attributes: HTML attributes for the page title element.
 * - title_prefix: Additional output populated by modules, intended to be
 *   displayed in front of the main title tag that appears in the template.
 * - title: The page title, for use in the actual content.
 * - title_suffix: Additional output populated by modules, intended to be
 *   displayed after the main title tag that appears in the template.
 */
#}
{{ title_prefix }}
{% if title %}
  <h1{{ title_attributes }}>{{ title }}</h1>
{% endif %}
{{ title_suffix }}

At this point, title is a render array. It is passed in as a Markup object. Where is this happening?

The span doesn't hurt anything, but at this point I just want to find where that is occurring. Is there an option to switch that off? I can preprocess_page_title and strip tag it, but unless there is a good reason, I would rather not have it at all.

Était-ce utile?

La solution

This is probably not the case for all pages? I think what you see is the rendered result of an entity field like for example this node field template:

field--node--title.html.twig:

<span{{ attributes }}>
  {%- for item in items -%}
    {{ item.content }}
  {%- endfor -%}
</span>

In other cases when the title is not bubbled up from the rendered main content and it is taken from the route definition there shouldn't be a span tag unless there is a title callback placing such a tag.

Licencié sous: CC-BY-SA avec attribution
Non affilié à drupal.stackexchange
scroll top