1

This PostHTML plugin "PostHTML Each" can repeat HTML code in a simple way. Like this

<!-- BEFORE -->
<div class="block" each="3"></div>

<!-- AFTER -->
<div class="block"></div>
<div class="block"></div>
<div class="block"></div>

How to repeat in a similar way in Nunjucks?

Jitendra Vyas
  • 148,487
  • 229
  • 573
  • 852
  • There's a for loop that you could probably use, see docs http://mozilla.github.io/nunjucks/templating.html#for – Molda Oct 05 '16 at 13:44

1 Answers1

2

I don't think there's a nice one-liner as in your example for PostHTML but as mentioned in the comment you can use for tag. It needs a data source to iterate over, so use it with range function which will provide such.

{% for i in range(0, 3) -%}
  <div class="block"></div>
{%- endfor %}

Docs:

Wojciech Czerniak
  • 1,261
  • 12
  • 17