4

I would like to create a custom template for the user profile view. With the help of "Theme debug" I figured out that I need to create a template named html--user.html.twig, but even if I copy all content of page.html.twig to my new template, I do get a blank page for any user profile now. Can anyone tell me what I'm doing wrong? I cleared all caches though.

Which content do I have to copy to a custom template (suggested file name)?

1 Answer 1

4

html--user.html.twig would be the template file used instead of html.html.twig when viewing a user profile (for example, for http://example.com/user/1). It is not the template file that shows the content of a user profile, but it's the template file that contains the basic structure of a Drupal page; in fact, its default content is the following one.

<!DOCTYPE html>
<html{{ html_attributes }}>
  <head>
    <head-placeholder token="{{ placeholder_token|raw }}">
    <title>{{ head_title|safe_join(' | ') }}</title>
    <css-placeholder token="{{ placeholder_token|raw }}">
    <js-placeholder token="{{ placeholder_token|raw }}">
  </head>
  <body{{ attributes }}>
    <a href="#main-content" class="visually-hidden focusable">
      {{ 'Skip to main content'|t }}
    </a>
    {{ page_top }}
    {{ page }}
    {{ page_bottom }}
    <js-bottom-placeholder token="{{ placeholder_token|raw }}">
  </body>
</html>

page.html.twig is the template file for a generic page; that is why you are getting a white page for user profile pages.

The template file for a user profile is user.html.twig, and its default content is the following one.

<article{{ attributes }}>
  {% if content %}
    {{- content -}}
  {% endif %}
</article>

As you see the variable it receives are completely different from the ones the other two template files (html.html.twig and page.html.twig) receive. That is why using the wrong template gives you a blank page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.