0

I've got a taxonomy page (https://www.dovericaricare.it/becharge) that I'm trying to customize using a twig template.

I don't understand what syntax I should use to print fields like the logo ({{ fields.field_logo }} doesn't work and there is nowhere in the dump a field with a full path url for the image) or the value of field_fornitore

Here's the dump of the content of the page (you can see it on the page itself too). Can you please suggest how to print values in twig template?

(I already did the same on a node page, but the taxonomy term seems a lot harder)

enter image description here

2
  • 2
    Normally you print just {{ content }} and use the vocabulary's display settings to put your fields in the right order and select the desired field formatters. Maybe together with some Field Groups if you need additional wrappers. You can also print {{ content.field_logo }} exclusively and later print the rest {{ content|without('field_logo) }}.
    – leymannx
    Jan 4, 2022 at 19:46
  • 2
    The variable would be {{ content.field_name }} to render a field.
    – Kevin
    Jan 4, 2022 at 19:47

2 Answers 2

1

Your field_logo has got a list (array), where is your logo. I would try

{{ content.field_logo[0] }}

If you want some helpful forum with more info about references (and entities for nodes as well) look there: https://www.drupal.org/forum/support/theme-development/2015-12-16/entity-reference-values-in-twig-template

0

this is the code I used at the end (don't remember how I get it, but I remember that KINT debugger helped me a lot):

{# start to cycle #}
{% for immagine in content.field_immagine_colonnine %}
    {% if immagine['#item'].target_id > 0 %}
        <div class="imagetext">
            <img alt="{{ immagine['#item'].alt }}" 
                title="{{ immagine['#item'].title }}" 
                src="{{ file_url(immagine['#item'].entity.uri.value | image_style('large') ) }}" 
                id="{{ immagine['#item'].target_id }}" 
            />
            <p class="sottotitoloimmagine">{{ immagine['#item'].title }}</p>
        </div>
    {% endif %}
{% endfor %}
{# end cycle #}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.