How do I know if a link has the "active" class? I've added a custom twig template for links--language-block.html.twig.

Inside of it, I want to render additional HTML when the current item is active. But I can't figure out how to check when the current item is active.

{% if links -%}
  {%- if attributes.hasClass('inline') -%}
  &lt;ul{{ attributes.addClass('list-inline') }}&gt;
  {%- else -%}
  &lt;ul{{ attributes }}&gt;
  {%- endif -%}
    {%- for key, item in links -%}

      {% if item.attributes.hasClass('is-active') %} &lt;&lt; this is always false
        &lt;li&gt;foobar&lt;/li&gt;
      {%- endif -%}

      &lt;li{{ item.attributes.addClass('dropdown') }}&gt;
        {%- if item.link -%}
          {{ item.link }}

          {# &lt;a class="dropdown-toggle" data-target="#" data-toggle="dropdown"&gt;Deutsch &lt;span class="caret"&gt;&lt;/span&gt;&lt;/a&gt; #}
        {%- elseif item.text_attributes -%}
          &lt;span{{ item.text_attributes }}&gt;{{ item.text }}&lt;/span&gt;
        {%- else -%}
          {{ item.text }}
        {%- endif -%}
      &lt;/li&gt;
    {%- endfor -%}
  &lt;/ul&gt;
{%- endif %}


How can I check if the link as the active class?
In some cases, the active state is not set by design due potential problems with caching. This behavior is documented in this change record. 


  Setting the active class is now an opt-in feature:  
  
  l() and LinkGenerator::generate() now have a set_active_class option that defaults to FALSE
  theme_links() now accepts a set_active_class key that defaults to FALSE
  Those links that you'd expect to get the active class set, do get it: menu links, language switching links …
  
  The output of l(), LinkGenerator::generate() and theme_links() no longer contains the active class, even if you do opt in. Instead, they get a data-drupal-link-system-path attribute, and if there's a GET query, they also get a data-drupal-link-query attribute…


In those cases, where it is not set on server side, you can take a look at core/misc/active-link.js to get an idea how to manipulate the active state on client side.