TWIG template for SVG media type

Created on 14 May 2024, 6 months ago
Updated 22 May 2024, 6 months ago

Hello,

Problem/Motivation

I added a Media SVG file in a taxonomy term.

I built a TWIG file to display it as a 'regular' node content field with this code:

<div class="item">
  <div class="icon-svg">{{ content.field_icon_svg }}</div>
  <div class="tag">{{ name }}</div>
</div>

That works fine, even in a custom view mode.

When building a node TWIG, I only can display the terme 'name'.
No way to display the SVG icon.

How to proceed?

💬 Support request
Status

Postponed: needs info

Version

2.3

Component

Code

Created by

🇫🇷France webmestre

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @webmestre
  • Status changed to Postponed: needs info 6 months ago
  • 🇪🇨Ecuador jwilson3

    When building a node TWIG, I only can display the terme 'name'. No way to display the SVG icon.

    I had to read this a few times to understand, and as far as I can tell, it appears your question might be confusing "node TWIG" for "Taxonomy TWIG"? since "term name" is for taxonomies and "node title" is for nodes.

    Anyway, I've tested both adding a field_svg_icon to a Taxonomy vocabulary as well as a Node type, and the custom templates work the same way in both cases.

    My template overrides:

    {#
    taxonomy-term--tags.html.twig
    #}
    <a href="{{ url }}">{{ name }}</a>
    
    {{ dump(content) }}
    <h2>Custom rendered icon here:</h2>
    {{ content.field_svg_icon }}
    
    {{ content|without('field_svg_icon') }}
    
    {{ dump(content) }}
    
    <h2>Custom rendered icon here:</h2>
    {{ content.field_svg_icon }}
    
    {{ content|without('comment')|without('field_svg_icon') }}
    

    Both work fine:

    My only suggestions are to ensure you've enabled the field_svg_icon in the correct display (eg Default, Full content, Teaser) on the "Manage Display" tab of your Content type and Taxonomy term config screens.

    I'm afraid I'd need more clear example of your configuration to help troubleshoot this any further. Marking postponed.

Production build 0.71.5 2024