How do I theme a link from a template file? A twig template is rendering a list of links that come with classes. The basic:

{{ mylink }}


twig code will output something like

&lt;a href="#" class="someclass" &gt;the text&lt;/a&gt;


Not all links have classes. I want to write a twig template that will instead output something like this:

&lt;a href="#" class="someclass" &gt;
  &lt;span class="sprite someclass" &gt;&lt;/span&gt;
  the text&lt;/a&gt;


What I've tried:


I looked for the twig template to override. Unfortunately it seems that links are not rendered by a twig template.
I tried updating the twig variable like

set mylink['#title'] = "&lt;span&gt;...&lt;/span&gt;" ~ mylink['#title']


But it won't let  me do that.
Here's a twig only solution for a particular field that needs this treatment;
it's not a generic solution for all links everywhere.

some-template.twig:

&lt;ul class="field--name-field-links"&gt;
  {% for item in content.field_links %}
  {% if item['#title'] %}
    &lt;li&gt;
      &lt;a href="{{ item['#url'] }}" class="{{ item['#options'].attributes.class|join(' ') }}" &gt;
        {% if item['#options']['attributes']['class'] %}
          &lt;span class="sprite {{ item['#options']['attributes']['class']|join(" ") }}"&gt;&lt;/span&gt;
        {% endif %}
        {{ item['#title'] }}
      &lt;/a&gt;
    &lt;/li&gt;
  {% endif %}
  {% endfor %}
&lt;/ul&gt;