<p>Not sure if you really wanted dynamic variable names like <code>imgurl1</code> or not, but something like this?</p>

<pre><code>&lt;div class="row"&gt;
{% for entry in entries %}
    {% set loopIndex = loop.index %}
    &lt;div&gt;&lt;p&gt;text{{loopIndex}}&lt;/p&gt;&lt;img src="{{ _context['imgurl' ~ loopIndex] }}" /&gt;&lt;/div&gt;
    {% if loopIndex is divisible by(3) %}
        {% if not loop.last %}
            &lt;/div&gt;
            &lt;div class="row"&gt;
        {% endif %}
    {% endif %}
{% endfor %}
&lt;/div&gt;
</code></pre>

CC BY-SA 4.0
2020-05-06T07:47:49.920Z
yes, it displays the correct HTML structure, thank you very much for your help.
Cosmin Ciolacu
CC BY-SA 4.0
2020-05-06T04:29:06.377Z
2020-05-06T04:29:06.377Z
Brad Bell
<p>I have an Matrix field and I want to extract data in the following HTML structure:</p>

<pre><code>&lt;div class="row"&gt;
  &lt;div&gt;&lt;p&gt;text1&lt;/p&gt;&lt;img src="{{imgurl1}}" /&gt;&lt;/div&gt;
  &lt;div&gt;&lt;p&gt;text2&lt;/p&gt;&lt;img src="{{imgurl2}}" /&gt;&lt;/div&gt;
  &lt;div&gt;&lt;p&gt;text3&lt;/p&gt;&lt;img src="{{imgurl3}}" /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class="row"&gt;
  &lt;div&gt;&lt;p&gt;text4&lt;/p&gt;&lt;img src="{{imgurl4}}" /&gt;&lt;/div&gt;
  &lt;div&gt;&lt;p&gt;text5&lt;/p&gt;&lt;img src="{{imgurl5}}" /&gt;&lt;/div&gt;
  &lt;div&gt;&lt;p&gt;text6&lt;/p&gt;&lt;img src="{{imgurl6}}" /&gt;&lt;/div&gt;
&lt;/div&gt;
</code></pre>

<p>and this is my twig code for retrieving data from craft:</p>

<pre><code>
{% for entry in entries %}
  {% if loop.index is divisible by(3) %}
     &lt;div class="row"&gt;
  &lt;div&gt;&lt;p&gt;text4&lt;/p&gt;&lt;img src="{{imgurl4}}" /&gt;&lt;/div&gt;
  &lt;div&gt;&lt;p&gt;text5&lt;/p&gt;&lt;img src="{{imgurl5}}" /&gt;&lt;/div&gt;
  &lt;div&gt;&lt;p&gt;text6&lt;/p&gt;&lt;img src="{{imgurl6}}" /&gt;&lt;/div&gt;
&lt;/div&gt;
{% else %}
 &lt;div&gt;&lt;p&gt;text4&lt;/p&gt;&lt;img src="{{imgurl4}}" /&gt;&lt;/div&gt;
  &lt;div&gt;&lt;p&gt;text5&lt;/p&gt;&lt;img src="{{imgurl5}}" /&gt;&lt;/div&gt;
  &lt;div&gt;&lt;p&gt;text6&lt;/p&gt;&lt;img src="{{imgurl6}}" /&gt;&lt;/div&gt;
{% endif %}
{% endfor %}
</code></pre>

<p>I want to output multiple browse with free divs
I am new to Craft and I will appreciate any help, thanks!</p>

<templating>
Templating data in HTML
# Templating data in HTML

(Asked by: username_0 on 2020-05-05)

I have an Matrix field and I want to extract data in the following HTML structure:

  text1
  text2
  text3


  text4
  text5
  text6


and this is my twig code for retrieving data from craft:

{% for entry in entries %}
  {% if loop.index is divisible by(3) %}
     
  text4
  text5
  text6

{% else %}
 text4
  text5
  text6
{% endif %}
{% endfor %}

I want to output multiple browse with free divs
I am new to Craft and I will appreciate any help, thanks!

**Tags:** templating

---

## 1 answers

### Answer by username_1 on 2020-05-06. Score: 1 | Accepted answer

Not sure if you really wanted dynamic variable names like imgurl1 or not, but something like this?

{% for entry in entries %}
    {% set loopIndex = loop.index %}
    text{{loopIndex}}
    {% if loopIndex is divisible by(3) %}
        {% if not loop.last %}
            
            
        {% endif %}
    {% endif %}
{% endfor %}

> **Comments:**
> **username_0**: yes, it displays the correct HTML structure, thank you very much for your help.  

---

