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?

Comments

webmestre created an issue. See original summary.

webmestre’s picture

Issue summary: View changes
jwilson3’s picture

Issue summary: View changes
Status: Active » Postponed (maintainer needs more info)
StatusFileSize
new560.71 KB
new629.2 KB

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') }}
{# node.html.twig #}
<a href="{{ url }}" rel="bookmark">{{ label }}</a>

{{ 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.

jwilson3’s picture

Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)

2 years old support request has been addressed/answered and no feedback from OP. Closing this as cannot reproduce.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.