Drupal - How do I override the title with the username?
Make Fields your format
Alternatively: if you are using the rendered entity row plugin check the
Force using fields
in the Format | Settings.In RELATIONSHIP, Add Content author
- Checkmark ☑ Require relationship
In FIELDS, add Name
- Checkmark ☑ Exclude from display
- Uncheck ☐ Link to the user
For TITLE put
{{ name }}'s blog
OR you could put it in your CONTEXTUAL FILTER; even though
{{ name }}
is not listed as a replacement pattern, it works (as long as you do step 1, 2, and 3).
Result
BONUS
If you want to capitalize the first letter of the user name use {{ name|capitalize }}'s blog
.
You can also add a Rendered Entity as a field.
You can switch the node's uid argument plugin to Drupal\user\Plugin\views\argument\Uid
, and get the same behaviour from that field instead. It would take a small amount of code in a custom module.
function MYMODULE_views_data_alter(&$data) {
$data['node_field_data']['uid']['argument']['id'] = 'user_uid';
}
Alternatively, if passing the author's username in the view URL is not a problem for you, since you have the author relationship set up, you can use the User: User ID
field for your filter instead of the one you're currently using. Because of the way its handler treats requests for titles, using {{ arguments.uid }}
in the "Override title" field will actually provide you with the username(s) instead of the ID(s).