Answers.Body: <p>If you're in the context of a Twig loop, you have access to the <a href="https://twig.symfony.com/doc/2.x/tags/for.html#the-loop-variable" rel="nofollow noreferrer"><code>loop</code> variable</a>, which has a number of “magic” properties set.</p>
  
  <p>This allows you to do something like:</p>
  
  <pre><code>{% set posts = craft.entries({ section: 'posts' }).all %}
  {% for post in posts %}
    Post #{{ loop.index }} is named: {{ post.title }}&lt;br&gt;
  {% endfor %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-21T01:40:59.117Z
Answers.LastActivityDate: 2018-06-21T01:40:59.117Z
Answers.UserDisplayName: August Miller
Body: <p>I need to assign a # 1-N for each entry that is returned -- i.e., 1, 2, 3, 4, ....   (This is for a sort plugin.)</p>
  
  <p>How do I template for that?</p>
  
Tags: <templating>
Title: Assign a number 1-N for each entry that is returned
ThreadText: # Assign a number 1-N for each entry that is returned
  
  (Asked by: username_0 on 2018-06-21)
  
  I need to assign a # 1-N for each entry that is returned -- i.e., 1, 2, 3, 4, .... (This is for a sort plugin.)
  
  How do I template for that?
  
  **Tags:** templating
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-06-21. Score: 1 | Accepted answer
  
  If you're in the context of a Twig loop, you have access to the [`loop` variable](https://twig.symfony.com/doc/2.x/tags/for.html#the-loop-variable), which has a number of “magic” properties set.
  
  This allows you to do something like:
  
  ```
  {% set posts = craft.entries({ section: 'posts' }).all %}
  {% for post in posts %}
    Post #{{ loop.index }} is named: {{ post.title }}<br>
  {% endfor %}
  
  ```
  
  
  ---
  
  