Twig not duplicate rows

Hello everyone,

again I am solving a problem that seemed solved and I can’t find a solution.

Please, how do I limit the generation of multiple variables below each other so that the result is not duplicated?

My form loads 1-5 folders, if I choose one, its name and link will be generated correctly, but if I choose two or more, the lists of folders below me will be displayed:

Example:

For one file:
(Correct)

* Show file: File.jpg

For 3 files:
(Problem)


* Show file: File.jpg
* Show file: File1.jpg
* Show file: File2.jpg

* Show file: File.jpg
* Show file: File1.jpg
* Show file: File2.jpg

* Show file: File.jpg
* Show file: File1.jpg
* Show file: File2.jpg

Code:

<ul>
  {% for val in value %}
  {% if val is iterable %}
  <ul>
    {% for item in form.value(field.name) %}
    <li>Show file: <a href="..//{{ string(item.path) }}" download target="_blank">{{ item.name }}</a></li>
    {% endfor %}
  </ul>
  {% else %}
  <li>{{ string(form.value(field.name))|nl2br }}</li>
  {% endif %}
  {% endfor %}
</ul>

this is the part of code from: “data.html.twig”

I try some like this: merge - Documentation - Twig - The flexible, fast, and secure PHP template engine
But not the solution.

How can I fix this, thank you all very much for their time.

@Deight, Like in a previous question, you are looping inside a loop…

The value of val is the same as the value for item. Drop the inner loop and replace item.path and item.name with val.path and val.name.

To debug what is happing inside a Twig template, use {{ dump(variable) }} and track the dumps in the ClockWork tab in the developer console of the browser.

I love you man, i am looping inside the loop, wow! Thank you very much.

Solution is call only variables not variables in variables:

{% for val in value %}
<a href="../{{ string(val.path) }}" download target="_blank"> {{ val.name }}</a><br>
{% endfor %}