How do I conditionally add a class to my page title within page-title.html.twig? I have a boolean field within my Page content type called Hide Title.

I need to conditionally add a class to h1's to visually hide them if this field is checked.

I have the following within page-title.html.twig

{% set hide_title = content.field_hide_title.0 %}

{% if 'On' in hide_title %}
    &lt;h1 {{ title_attributes.addClass('visually-hidden') }}&gt;{{ title }}&lt;/h1&gt;
{% else %}
  &lt;h1{{ title_attributes }}&gt;{{ title }}&lt;/h1&gt;
{% endif %}


This is is not adding the class while the boolean is set on or off.
In page-title.html.twig you don't have access to content variable.
according to page-title.html.twig comment section:  

Available variables are:


title_attributes
title_prefix 
title 
title_suffix


So you should implement hook_preprocess_HOOK to passe hide_title to your twig like the following:

/**
 * Implements hook_preprocess_HOOK().
 */
function MYMODULE_preprocess_page_title(&amp;$variables) {
  if ($node = \Drupal::routeMatch()-&gt;getParameter('node')) {
    $variables['hide_title'] = $node-&gt;field_hide_title-&gt;value;
  }
}


Now you can do the following in your twig:

{% if hide_title == "1" %}
    &lt;h1 {{ title_attributes.addClass('visually-hidden') }}&gt;{{ title }}&lt;/h1&gt;
  {% else %}
    &lt;h1{{ title_attributes }}&gt;{{ title }}&lt;/h1&gt;
{% endif %}