<p>So after reading Robin's answer, I realized I misread your question entirely... so the below isn't addressing your question exactly.</p>

<p>I initially deleted it, but I think it may be relevant information anyway, if you decide to eager load elements into your template, or you try to use the same query more than once.</p>

<p>.....</p>

<p>When you have something like <code>entry.imageGallery</code> you actually have an <a href="https://docs.craftcms.com/v3/dev/element-queries/" rel="nofollow noreferrer">ElementQuery</a> -- when you invoke the <code>.all()</code> method on that query, you're returned and array of results... so <code>entry.imageGallery</code> then changes from being an ElementQuery to a simple array.</p>

<p>That's why you're getting the error message that you are; you're trying to invoke an ElementQuery on what is now an array.</p>

<p>So you have a few options here, but I think the best option is to just realize that once you've retrieved these things from the ElementQuery (or even better, have <a href="https://nystudio107.com/blog/speed-up-your-craft-cms-templates-with-eager-loading" rel="nofollow noreferrer">Eager Loaded</a> them), they are now an array.</p>

<p>So let's treat them like an array, and modify our loop use the Twig slice <a href="https://twig.symfony.com/doc/2.x/filters/slice.html" rel="nofollow noreferrer">filter</a> to use just the items we want:</p>

<pre><code>{% for image in entry.imageGallery | slice(1) %}
</code></pre>

<p>...or you can use the shorthand notation:</p>

<pre><code>{% for image in entry.imageGallery[1:] %}
</code></pre>

CC BY-SA 4.0
2018-08-13T19:46:51.033Z
If I use the slice filter as you suggest it works but I get a depreciation error of:
"Looping through element queries directly has been deprecated. Use the all() function to fetch the query results before looping over them."
Paul Frost
CC BY-SA 4.0
2018-08-13T23:54:06.380Z
I was _assuming_ that you had already executed that ElementQuery somewhere, or the elements had been eager loaded, which would mean that they are arrays already. If not, tack `.all()` on the end
andrew.welch
CC BY-SA 4.0
2018-08-14T09:07:49.777Z
It's an assets field on a single entry template so I thought everything was already loaded. But re-reading your Eager Loading blog post I see that I need to pre-load the matrix fields as a separate process. This is an example of where I find Craft less than easy to understand and requiring lots of code for what seems like a simple template.
Paul Frost
CC BY-SA 4.0
2018-08-13T18:17:29.810Z
2018-08-13T23:52:58.097Z
2018-08-13T23:52:58.097Z
andrew.welch
<pre><code>{% for image in entry.imageGallery.offset(1).all() %}
</code></pre>

<p>Don't search for an example "how to apply <code>offset</code>". All properties work the same - there is nothing special/ no difference between <code>offset</code>, <code>limit</code>, a field value or anything else.</p>

CC BY-SA 4.0
2018-08-13T19:40:12.460Z
I had tried {% for image in entry.imageGallery.all().offset(1) %} and got a twig runtime error of "Impossible to invoke a method ("offset") on an array." I thought I had tried it both ways but obviously hadn't. But not being able to find any example or mention of using offset made me wonder if it had been dropped. I'm finding so many minor changes required for Craft 3 that are not obvious to me how to update my old code. I spent hours yesterday trying to update a conditional query comparing 2 dates. It doesn't help that SE doesn't separate between Craft 2 and 3.
Paul Frost
CC BY-SA 4.0
2018-08-13T19:43:46.700Z
Feel free to join slack so you can ask for those scenarios much faster. Besides that Andrew's answer is really good in terms of understanding what you actually do. All in all Craft 3 has not many differences between Craft 2. As long as you understood what you did in  Craft 2 it should be easy.
Robin Schambach
CC BY-SA 4.0
2018-08-13T19:50:22.217Z
I guess the problem is that sometimes I didn't really understand how it was working, I had help from people like you or copy/pasted examples from solutions posted. I can usually work out how to ammend an existing example but struggle to write code from scratch.
Paul Frost
CC BY-SA 4.0
2018-08-13T18:12:54.293Z
2018-08-13T18:12:54.293Z
Robin Schambach
<p>In Craft 2 I used:</p>

<pre><code>{% for image in entry.imageGallery.offset(1) %}
</code></pre>

<p>to exclude the first image, as that is shown higher up in the template.
I get the depreciation error of:</p>

<blockquote>
  <p>Looping through element queries directly has been deprecated. Use the
  all() function to fetch the query results before looping over them.</p>
</blockquote>

<p>So I changed it to:</p>

<pre><code>{% for image in entry.imageGallery.all() %}
</code></pre>

<p>But I can't find any example of how to apply an 'offset' in the Craft 3 docs.</p>

<craft3>
How do I use offset in Craft 3?
# How do I use offset in Craft 3?

(Asked by: username_0 on 2018-08-13)

In Craft 2 I used:
{% for image in entry.imageGallery.offset(1) %}

to exclude the first image, as that is shown higher up in the template.
I get the depreciation error of:

Looping through element queries directly has been deprecated. Use the
  all() function to fetch the query results before looping over them.

So I changed it to:
{% for image in entry.imageGallery.all() %}

But I can't find any example of how to apply an 'offset' in the Craft 3 docs.

**Tags:** craft3

---

## 2 answers

### Answer by username_2 on 2018-08-13. Score: 4 | Accepted answer

{% for image in entry.imageGallery.offset(1).all() %}

Don't search for an example "how to apply offset". All properties work the same - there is nothing special/ no difference between offset, limit, a field value or anything else.

> **Comments:**
> **username_0**: I had tried {% for image in entry.imageGallery.all().offset(1) %} and got a twig runtime error of "Impossible to invoke a method ("offset") on an array." I thought I had tried it both ways but obviously hadn't. But not being able to find any example or mention of using offset made me wonder if it had been dropped. I'm finding so many minor changes required for Craft 3 that are not obvious to me how to update my old code. I spent hours yesterday trying to update a conditional query comparing 2 dates. It doesn't help that SE doesn't separate between Craft 2 and 3.  
> **username_2**: Feel free to join slack so you can ask for those scenarios much faster. Besides that Andrew's answer is really good in terms of understanding what you actually do. All in all Craft 3 has not many differences between Craft 2. As long as you understood what you did in  Craft 2 it should be easy.  
> **username_0**: I guess the problem is that sometimes I didn't really understand how it was working, I had help from people like you or copy/pasted examples from solutions posted. I can usually work out how to ammend an existing example but struggle to write code from scratch.  

---

### Answer by username_1 on 2018-08-13. Score: 4

So after reading Robin's answer, I realized I misread your question entirely... so the below isn't addressing your question exactly.
I initially deleted it, but I think it may be relevant information anyway, if you decide to eager load elements into your template, or you try to use the same query more than once.
.....
When you have something like entry.imageGallery you actually have an ElementQuery -- when you invoke the .all() method on that query, you're returned and array of results... so entry.imageGallery then changes from being an ElementQuery to a simple array.
That's why you're getting the error message that you are; you're trying to invoke an ElementQuery on what is now an array.
So you have a few options here, but I think the best option is to just realize that once you've retrieved these things from the ElementQuery (or even better, have Eager Loaded them), they are now an array.
So let's treat them like an array, and modify our loop use the Twig slice filter to use just the items we want:
{% for image in entry.imageGallery | slice(1) %}

...or you can use the shorthand notation:
{% for image in entry.imageGallery[1:] %}

> **Comments:**
> **username_0**: If I use the slice filter as you suggest it works but I get a depreciation error of: "Looping through element queries directly has been deprecated. Use the all() function to fetch the query results before looping over them."  
> **username_1**: I was _assuming_ that you had already executed that ElementQuery somewhere, or the elements had been eager loaded, which would mean that they are arrays already. If not, tack `.all()` on the end  
> **username_0**: It's an assets field on a single entry template so I thought everything was already loaded. But re-reading your Eager Loading blog post I see that I need to pre-load the matrix fields as a separate process. This is an example of where I find Craft less than easy to understand and requiring lots of code for what seems like a simple template.  

---

