Role based User profile template I would like to have a different user template for each role, but I can't figure it out how do do it.

I've added a preprocess function in my themename.theme like this:

function ras_preprocess_page(&amp;$variables) {

    $variables['role'] = \Drupal::currentUser()-&gt;getRoles();
}


and then used role in my user.html.twig like this: 

{% if role == 'administrator' %}
   &lt;p&gt;Hello, admin&lt;/p&gt;
{% elseif role == 'anonymous' %}
   &lt;p&gt;Hi, stranger&lt;/p&gt;
{% endif %}


But it doesn't work as I would expect.
You can use hook_theme_suggestions_HOOK_alter() like below:

/**
 * Implements hook_theme_suggestions_HOOK_alter().
 */
function THEME_NAME_theme_suggestions_user_alter(array &amp;$suggestions, array $variables) {
  $roles = \Drupal::currentUser()-&gt;getRoles();
  if (in_array('YOUR ROLE',$roles)) {
    $suggestions[] = 'user__'.ROLENAME;
  }
}


and you have to create 


  user--YOURROLE.html.twig


in order to get a specific template for the user based on their role.