theming – You do not know how to extract the twig variables

Try using twig variables (simple strings) in a template that I have created from a custom module. By using devel and KINT, I can see the info under the Iterator content with

{{kint (transaction[0])}}

enter the description of the image here

I can not get the template to print on the page. I have tried

 $ {{transaction.amount}} total donation

and $ {{transaction[0].montant}} total donation

Anyway, empty. Not sure what I'm missing here. It works very well in other modules. Maybe I'm too high on twig models? I do not quite understand the tree. I created a template called transaction.html.twig.


This is what my controller looks like.

enter the description of the image here

theming – How to display custom taxonomy fields in field twig

In my content type for Event, I have an entity reference called Speakers that refers to a taxonomy called Team Members. It is set to several so that I can tell which speakers belong to my event. On the detail page of the event, I wish to list the speakers with all their fields.

I have a hook called field-field-speakers.html that lists all the speakers. I do not seem to be able to get any of the fields in the taxonomy. (ex: item.content.field_job_title) It does not display any content.

        {% for the article in the articles%}

{{}} Item.content
{{}} Item.content.field_job_title
{% endfor%}

How can I do this? I think the answer might be in a view, but you do not know how to map it dynamically based on the event I'm in.

symfony – How can I increase indexes in nested loops in twig?

What I want would be easily solved in other programs with an (i ++)
but it does not work well for me.

This code explains what I want to do (the key is at line 4):

{% for i in 0..5%}

{% for j in 0..2%} columns #}
{% i ++%} {# ~ line 4 ~ #}
{% if (i + 1) is divisible by (3)%}
{% set colum = & # 39; last & # 39;%}
{% else%}
{% set colum = noLast%%
{% endif%}

Title {{i}}

    {% for u in 0..10%}

  • Coffee {{u}}
  • {% endfor%}

{% endfor%} #}

{% endfor%}

The fact is that I can not use loop.index because the loops are nested.
in line 4, I've also tried to use:

  1. {% i = i + 1%}
  2. {% set i = i + 1%}


  1. It says: unexpected "i" tag (closing tag for the "for" tag set near line 667).
  2. I do not keep the value of i, when the loop starts again, it restarts the value where it was going.

Have that if you give me ideas.
Thanks in advance.

How to check if the result of the view is empty, Twig

To check the field, I use the following code:

{% if happy.file_name | render is empty%}

How to check on node.twig if {{}} My_cool_view the result is empty? Is this usually possible in Drupal 8? Thanks for the help.

theming – get values ​​on twig node pattern

I have installed the ECK module on my website. In using it, I created an entity "report eck" in which I have different sets such as section, notes, etc., each containing different fields.
I have my type of content "Report" in which I referred "report eck" entity to the help of the entity reference field.
Now, in my beautiful model, I have to get various values, including the type of package, in which I encounter a lot of problems. My package type comes as follows when I'm doing kint () on my reference field, but I can not get this type of package and many other values, please guide.
enter the description of the image here

In addition, it seems to be a protected value. I've therefore navigated through the "Available Methods" tabs and found the "getEntityKey ()" method that seems to be useful, but how can I use it in a twig template?

enter the description of the image here

How to add options and classes to a custom attribute in Twig?

In our twig model, we need to wrap some fields with Link field. In the existing twig model there is already a attributes variable (accessible by adding attributes), but we need to have one customized. Can not find documentation about the ability to pass options and attributes of a field to a custom file. attribute branch.

Is there a way to add everything options and Classes from a field attributes in a custom attribute in a Twig model without any hook_preproceess_hook?

Existing node - article.html.twig

{{}} Content.body
{{}} Content.field_subtitle
{{}} Content.field_category
{{content.field_link}} / * has its own options and attributes * /

Desired output

/ * passes the options and attributes of field_link in the a_attr * /
/ * It did not work out what we wanted * /
{% set a_attr = create_attribute (content.field_link.0['#attributes'])%}

{{}} Content.body
{{}} Content.field_subtitle
{{}} Content.field_category
{{Content.field_link.0['#title'] }}

8 – How to insert fields in a link field in twig?

We have several fields on our article type of content, one of which is a Link field. In one twig model we would like to display a

so that everything is clickable with different fields inside it.

Current node - article.html.twig

{{}} Content.body
{{}} Content.field_subtitle
{{}} Content.field_category

Amended node - article.html.twig model to do everything

clickable (desired output).

{{}} Content.body
{{}} Content.field_subtitle
{{}} Content.field_category

Is there another way for me to do that?

I was looking for something similar to below. He would release what is under the Modified Node - article.html.twig (above)

{{link (label, url) | insert (content.body, content.field_subtitle, content.field_category)}}

datetime – My date in Twig ignores the format

I have a twig file with the following code on my Drupal 8.4.4 site:

{{}} Node.field_date.value

And in my type of content, manage the display option, I formatted it like this:
enter the description of the image here

But on the website, that indicates the date

2019-01-16T23: 00: 00

What do I miss?

views – how to spread a message in twig?

In my page.html.twig

{% block content%}
{{}} Page.breadcrumb
{{Content of the page['shop_page_title'] }} {{Content of the page['shop_content'] }}
{{Content of the page['shop_page_title'] }} {{Content of the page['shop_content'] }}