Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
In the node template, we want the node title to be output as follows:
{{ title.prefix }}
{% if not page %}
<h2{{ title.attributes }}><a href="{{ url }}" rel="bookmark">{{ title.label }}</a></h2>
{% endif %}
{{ title.suffix }}
But changing the title prefix and suffix should be done globally, and will affect many other templates as well, thus this separate issue.
Comments
Comment #1
jenlamptonThis change also applies to attributes, content_attributes (should be content.attributes) and title_attributes (should be title.attributes)
Comment #2
star-szrChanging to normal since there hasn't been much movement and we'd need to determine what would happen when
{{ title }}
is placed in the template. We talked about this on the Twig call and it seems like we'd need to introduce another theme function or template and we're trying to move away from very granular theme functions and templates.Comment #3
mortendk CreditAttribution: mortendk commentedcould we rename it {{ title.prefix }} & {{ title.suffix }} to something that makes sense ?
afaik it dosnt have anything to do with the title
rename:
Comment #4
lauriiiThis sounds a bit Classy issue. However this is something we can't do anymore for Drupal 8.
Comment #5
catchSpoke to Cottser about this and it might be doable in a minor release with bc, so moving back down.
Comment #9
BerdirCreated #2943911: Figure out what to do with title prefix/title_suffix in entity templates, I think I outlined a plan there that could work in a minor release, input from frontend people very welcome. I think this could possibly be closed as a duplicate.
Comment #10
xmacinfoI believe this is not a duplicate.
It's not only a question of {{ title.prefix }} and {{ title.suffix }}, but of also renaming some of the other title variables.For example, when a themer or a front-end want to display the title it may not make sense for him to output {title.label} in twig.
He or she may assume that the {title.label} variable will display “Title” and that {title} or {title.value} will display the correct title value.
The overall {title} twig context should be reviewed.
Comment #11
BerdirThere is no title.label, just label. And we are starting to deprecate that in #2923701: Mechanism to disable preprocessing of node base fields so they can be configured via the field UI where title will be like any other field, aka content.title.
Comment #21
markconroy CreditAttribution: markconroy at Annertech commentedLet's move this to Classy.