Score:0

How can I print a single field?

cn flag

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

leymannx avatar
ne flag
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](https://www.drupal.org/project/field_group) if you need additional wrappers. You can also print `{{ content.field_logo }}` exclusively and later print the rest `{{ content|without('field_logo) }}`.
Kevin avatar
in flag
The variable would be {{ content.field_name }} to render a field.
Score:1
bv flag

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

Score:0
cn flag

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 #}
Score:-2
cn flag

According to the dump of content which is shown ahead I would try to print a single field in the twig template like this:

{{ term.fields.field_logo.values }}
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.