title: How to get a certain number of elements in django template
body: <p>I wonder how I can get a specific number of items when i put an if statement inside a for loop </p>
  
  <p>i know we can do <code>{% for i in items|slice ":5"%}</code> to get a number of items but when i do</p>
  
  <pre><code>{% for post in posts %}
      {% for img in post_imgs %}
          {% if img.link == post.link %}
              &lt;img class="class" src="{{img.img.url}}" style="width:100%"&gt;
          {% endif %}
      {% endfor %}
  {% endfor %}
  </code></pre>
  
  <p>there's no way of doing that inside the if tag .. any solution</p>