> For the complete documentation index, see [llms.txt](https://mariohernandez.gitbook.io/components/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mariohernandez.gitbook.io/components/drupal-integrations/author.md).

# Author integration

Out of the box Drupal does not provide template suggestions for users. After researching a little I found a hook alter that will allow us to create new template suggestions.

1. In your editor, open `training_theme.theme` which is located in the root of your theme
2. Add the following code:

{% tabs %}
{% tab title="training\_theme.theme" %}

```php
/**
 * Implements hook_theme_suggestions_user_alter().
 *
 *   An array of alternate, more specific names for template files or theme
 *   functions for users.
 */
function training_theme_theme_suggestions_user_alter(&$suggestions, $vars, $hook) {

  // Define the view mode.
  $mode = $vars['elements']['#view_mode'];

  // Create a theme hook suggestion which has the view mode name in it.
  $suggestions[] = 'user__' . $mode;
}
```

{% endtab %}
{% endtabs %}

* The hook alter above will make it possible for Drupal to provide some useful twig template suggestions.
* Clear Drupal's cache
* Inspect the user by right-clicking over the user's picture and selecting **Inspect** or **Inspect Element**
* As you scroll through the debugging info in your inspector you should be able to see template suggestions for users. See screenshot:

![User template suggestions](/files/-M8ThuYFRSzd_aHR317H)

* By default Drupal uses `user.html.twig` to render all users. Thanks to the hook alter we added earlier we now see a new template suggestion, `user--author.html.twig`. This template is using the new view mode we created for our users earlier.
* Copy `user.html.twig` from the path shown in the image above (`core/themes/stable/templates/user/`, into your theme's `/templates/user` folder
* Rename the newly copied template `user--author.html.twig`
* Clear Drupal's cache
* If you reload the homepage again and inspect the user you should see our new template suggestion being used by Drupal.

## Integrating the Author component

1. Open `user--author.html.twig` in your editor and as we've done with all template suggestions, delete all the code except the comments
2. Add the following code and save the file

{% tabs %}
{% tab title="user--author.html.twig" %}

```php
{% include "@training_theme/author/author.twig" with
  {
    "attributes": attributes,
    "author": {
      "photo": content.user_picture,
      "name": content.field_full_name,
      "title": content.field_title
    }
  }
%}
```

{% endtab %}
{% endtabs %}

* Reload Drupal's homepage and you should now see the author information properly themed.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://mariohernandez.gitbook.io/components/drupal-integrations/author.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
