How to override a twig template for only a specific page? The title of this user view page contains the name of the user. I want modify it and, thanks to twig debug, I see the template used is page-title.html.twig: 

{% if title %}
  &lt;h1{{ title_attributes.addClass('page-header') }}&gt;{{ title }}&lt;/h1&gt;
{% endif %}


If I override it, how can I make twig use my overrided template only in the user view page?
As you mentioned your main issue is whatever data you are fetching it is overriding the all page-title on the site which you do not want. So to solve that follow following steps,

For common understanding I am referring bartik theme. I am showing with example to my local site so it will be very practical to understand.

In bartik.theme file,

function bartik_preprocess_page_title(&amp;$variables) {
  $variables['staticString'] = 'Explorer ';
  $variables['user_profile_view'] = (\Drupal::routeMatch()-&gt;getRouteName() == 'entity.user.canonical'); }


in page-title.html.twig file,

{% if title %}
  {% if user_profile_view %}
    &lt;h1{{ title_attributes.addClass('page-header') }}&gt;{{ staticString }}{{ title }}&lt;/h1&gt;
  {% else %}
    &lt;h1{{ title_attributes.addClass('page-header') }}&gt;{{ title }}&lt;/h1&gt;
  {% endif %}
{% endif %}


Output image,
On user page,


  


On other page(It will not interfere),


  


So, this way you can Override the page-title of user-profile page and can insert your own defined variable. So, this answer is with static variable, now same way, you have to just replace that variable with your dynamic variable, so it will get change based on your code.

Note: In solving this question, I have asked another question here: How to get the part of URI and pass it to as a argument?.