Answers.Body: <p><code>loop.index</code> and <code>loop.index0</code> will <a href="http://twig.sensiolabs.org/doc/tags/for.html#the-loop-variable" rel="nofollow noreferrer">both return integers</a>.</p>
  
  <p>So when you do <code>{% set previous = loop.index - 1 %}</code>, on the first iteratin of that loop, <code>loop.index</code> returns <code>1</code>, then you subtract <code>1</code> from it and <code>previous</code> is now equal to <code>0</code>.</p>
  
  <p>Later you call <code>previous.url()</code>, which is equal to <code>0.url()</code> and the error message you get says there is no method named <code>url()</code> for the integer <code>0</code>.</p>
  
  <p>If you want to access the previous <em>row</em>, then you can probably do something like <code>{% set previousRow = module.contents[previous] %}</code>.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-11-29T19:16:06.883Z
Answers.LastActivityDate: 2016-11-29T19:16:06.883Z
Answers.UserDisplayName: Brad Bell
Body: <p>Very new to Craft &amp; Twig. So I get the following error: <em>Impossible to invoke a method (&quot;url&quot;) on a integer variable (&quot;0&quot;)</em> with the below code:</p>
  <pre class="lang-html prettyprint-override"><code>{% if module.type == &quot;rotator&quot; %}
      &lt;div class=&quot;rotator&quot;&gt;
          {% for row in module.contents %}
              {% set position = loop.index0 %}
              {% set previous = loop.index -1 %}
              {% set next = loop.index + 1 %}
              &lt;div class=&quot;rotator__item active&quot;&gt;
                  &lt;img src=&quot;{{ row.slideImage.first().url}}&quot; alt=&quot;slideImage.title&quot;&gt;
              &lt;/div&gt;
              &lt;div class=&quot;switcher&quot;&gt;
                  &lt;span class=&quot;rotator__control left&quot;&gt;
                      &lt;a href=&quot;{{ previous.url() }}&quot;&gt; ‹&lt;/a&gt;
                  &lt;/span&gt;
                  &lt;span class=&quot;previous__title&quot;&gt;
                      {{ previous.slideTitle }}
                  &lt;/span&gt;
                  &lt;div class=&quot;divider&quot;&gt;
                  &lt;/div&gt;
                  &lt;span class=&quot;content&quot;&gt;
                      &lt;p&gt;{{row.slideTitle}}&lt;/p&gt;
                      &lt;a href=&quot;row.slideImage.first().url&quot;&gt;
                          {{row.slideCaption}}
                      &lt;/a&gt;
                  &lt;/span&gt;
                  &lt;span class=&quot;rotator__control right&quot;&gt;
                      {{ next.slideTitle }}
                  &lt;span&gt;
                      &lt;a href=&quot;{{ next.url() }}&quot;&gt; ›&lt;/a&gt;
                  &lt;/span&gt;
              &lt;/div&gt;
          {% endfor %}
      &lt;/div&gt;
  {% endif %}
  </code></pre>
  <p>So basically I need a 'previous' and 'next' variable that corresponds to the previous row and the next row in the Super Table. Essentially I need a way to call the current row in the Super Table I'm at, and the previous row and next row relative to the row I'm on.</p>
  <p>Here's what my set up looks like:</p>
  <p><a href="https://i.sstatic.net/JAB2I.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/JAB2I.png" alt="enter image description here" /></a></p>
  <p><a href="https://i.sstatic.net/Pj71H.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/Pj71H.png" alt="enter image description here" /></a></p>
  <p>I've tried loop.index0 + 1 and loop.index + 1. But neither work and I know I am calling them in the wrong way.</p>
  
Tags: <templating><forloop><plugin-supertable>
Title: Looping through rows in a Super Table
ThreadText: # Looping through rows in a Super Table
  
  (Asked by: username_0 on 2016-11-29)
  
  Very new to Craft & Twig. So I get the following error: *Impossible to invoke a method ("url") on a integer variable ("0")* with the below code:
  
  ```html
  {% if module.type == "rotator" %}
      <div class="rotator">
          {% for row in module.contents %}
              {% set position = loop.index0 %}
              {% set previous = loop.index -1 %}
              {% set next = loop.index + 1 %}
              <div class="rotator__item active">
                  <img src="{{ row.slideImage.first().url}}" alt="slideImage.title">
              </div>
              <div class="switcher">
                  <span class="rotator__control left">
                      <a href="{{ previous.url() }}"> ‹</a>
                  </span>
                  <span class="previous__title">
                      {{ previous.slideTitle }}
                  </span>
                  <div class="divider">
                  </div>
                  <span class="content">
                      <p>{{row.slideTitle}}</p>
                      <a href="row.slideImage.first().url">
                          {{row.slideCaption}}
                      </a>
                  </span>
                  <span class="rotator__control right">
                      {{ next.slideTitle }}
                  <span>
                      <a href="{{ next.url() }}"> ›</a>
                  </span>
              </div>
          {% endfor %}
      </div>
  {% endif %}
  
  ```
  
  So basically I need a 'previous' and 'next' variable that corresponds to the previous row and the next row in the Super Table. Essentially I need a way to call the current row in the Super Table I'm at, and the previous row and next row relative to the row I'm on.
  
  Here's what my set up looks like:
  
  [![enter image description here](https://i.sstatic.net/JAB2I.png)](https://i.sstatic.net/JAB2I.png)
  
  [![enter image description here](https://i.sstatic.net/Pj71H.png)](https://i.sstatic.net/Pj71H.png)
  
  I've tried loop.index0 + 1 and loop.index + 1. But neither work and I know I am calling them in the wrong way.
  
  **Tags:** templating, forloop, plugin-supertable
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-11-29. Score: 1
  
  `loop.index` and `loop.index0` will [both return integers](http://twig.sensiolabs.org/doc/tags/for.html#the-loop-variable).
  
  So when you do `{% set previous = loop.index - 1 %}`, on the first iteratin of that loop, `loop.index` returns `1`, then you subtract `1` from it and `previous` is now equal to `0`.
  
  Later you call `previous.url()`, which is equal to `0.url()` and the error message you get says there is no method named `url()` for the integer `0`.
  
  If you want to access the previous *row*, then you can probably do something like `{% set previousRow = module.contents[previous] %}`.
  
  
  ---
  
  