Drupal - How do I override the title with the username?

  1. Make Fields your format

    enter image description here

    Alternatively: if you are using the rendered entity row plugin check the Force using fields in the Format | Settings.

  2. In RELATIONSHIP, Add Content author

    • Checkmark ☑ Require relationship
  3. In FIELDS, add Name

    • Checkmark ☑ Exclude from display
    • Uncheck ☐ Link to the user
  4. For TITLE put {{ name }}'s blog

    enter image description here

    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).

    enter image description here

Result

enter image description here

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.

enter image description here

enter image description here


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).

Tags:

Views