Answers.Body: <p>As <a href="https://craftcms.stackexchange.com/a/782/57">Victor rightfully points out</a>, the {% paginate %} tags require an ElementCriteriaModel, so you can't do what you're doing in your first example because as soon as you call:</p>
  
  <pre><code>{% for databyte in allDatabytes %}
  </code></pre>
  
  <p>Craft hits the database and converts the ElementCriteriaModel into actual EntryModels.</p>
  
  <p>We also don't have support, yet, for passing <code>:empty:</code> into things like AssetFields, TagFields, etc., which is why your second example won't work...  however that is on our list to add!</p>
  
  <p>In this case, I think your best bet is going to be to do through the search service with something like this:</p>
  
  <pre><code>{# Search for 10 entries in the 'databytes' section where the 'series' assetField doesn't have anything selected. #}
  {% set myCriteria = craft.entries.section('databytes').search('-series:*').limit(10) %}
  
  {% paginate myCriteria as entries %}
      {% for entry in entries %}
          {{ entry.title }}
      {% endfor %}
  
      {% if paginate.prevUrl %}
          &lt;a href="{{ paginate.prevUrl }}"&gt;Previous Page&lt;/a&gt;
      {% endif %}
  
      {% if paginate.nextUrl %}
          &lt;a href="{{ paginate.nextUrl }}"&gt;Next Page&lt;/a&gt;
      {% endif %}
  {% endpaginate %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-09T04:59:12.290Z
Answers.Text: Hi Brad, thank you that worked great. Its good to see there is so many different ways to attack a problem.
Answers.UserDisplayName: Gareth
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-08T22:45:38.210Z
Answers.LastActivityDate: 2014-07-08T22:45:38.210Z
Answers.LastEditDate: 2017-04-13T12:51:00.253Z
Answers.UserDisplayName: Brad Bell
Answers.Body: <p>This won't work with your example, because the <a href="http://buildwithcraft.com/docs/templating/tags#paginate" rel="nofollow noreferrer">pagination-tag</a> only accepts an <a href="http://buildwithcraft.com/docs/templating/elementcriteriamodel" rel="nofollow noreferrer">ElementCriteriaModel</a>, not an array of already fetched entries:</p>
  
  <pre class="lang-twig prettyprint-override"><code>{% paginate MyCriteria as PageSubset %}
  </code></pre>
  
  <p>See also: <a href="https://craftcms.stackexchange.com/q/265/177">What are the differences between an elementCriteriaModel and fetched elements?</a></p>
  
  <hr>
  
  <p>If I understand your code correctly, you want to get all entries which have an empty <code>series</code>-field? </p>
  
  <p>If so, you don't have to fetch all entries and check against it, you can just add this to the <a href="http://buildwithcraft.com/docs/templating/elementcriteriamodel" rel="nofollow noreferrer">ElementCriteriaModel</a>:</p>
  
  <pre class="lang-twig prettyprint-override"><code>{% set MyCriteria = craft.entries.section('databytes').series(':empty:') %}
  
  {% paginate MyCriteria as entries %}
  ....
  {% endpaginate %}
  </code></pre>
  
  <hr>
  
  <p><strong>Why does the pagination tag need a CriteriaModel?</strong></p>
  
  <p>An ElementCriteriaModel can be compared to a sql query, it specifies what elements/entries to fetch (it sets the criteria). If you <a href="http://buildwithcraft.com/docs/templating/elementcriteriamodel#outputting-elements" rel="nofollow noreferrer">treat your CriteriaModel as an array or append .first()</a> it will fetch those entries and replace the results with the CriteriaModel.</p>
  
  <p>The <a href="http://buildwithcraft.com/docs/templating/tags#paginate" rel="nofollow noreferrer">pagination-tag</a> needs a CriteriaModel (or "query") because it adds an offset (to the "query") depending on what page you are on, and then fetches the entries. - That's why the pagination-tag doesn't work with already fetched entries.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-07T13:40:25.627Z
Answers.Text: Hi Victor, thank you, that looks like just the solution I am after. I spent ages trying to figure out what I came up with to. Sorry but how Craft works with ElementCriteriaModels is till very confusing to me and I have read the docs and Stuarts post a few times. Could you expand on your example as the only pagination example I have is http://buildwithcraft.com/docs/templating/tags#paginate and I can't figure what to add to your solution to make it work. Many thanks for your help.
Answers.UserDisplayName: Gareth
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-07T15:52:51.693Z
Answers.Text: I added an explanation for the CriteriaModel. Copying the example pagination-code from the docs inside my example should work fine, what problems do you have exactly?
Answers.UserDisplayName: Victor
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-07T16:14:23.557Z
Answers.Text: Hi Victor, thank you for the explanation and I have updated my example to show you what I have which currently displays no results.
Answers.UserDisplayName: Gareth
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-07T16:26:52.927Z
Answers.Text: I tested your code and it worked in my test. What field type is `series` and what does it contain?
Answers.UserDisplayName: Victor
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-07T16:45:24.360Z
Answers.Text: `series` is an entries field type: http://buildwithcraft.com/docs/entries-fields and can contain multiple related entries.
Answers.UserDisplayName: Gareth
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-07T16:55:27.923Z
Answers.Text: Can you remove `.series(':empty:')` to check if all entries are fetched. If so, can you make sure that there is an entry where the `series` field is empty.
Answers.UserDisplayName: Victor
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-07T17:07:06.853Z
Answers.Text: Let us [continue this discussion in chat](http://chat.stackexchange.com/rooms/15587/discussion-between-gareth-redfern-and-victor-in).
Answers.UserDisplayName: Gareth
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-07T13:11:44.463Z
Answers.LastActivityDate: 2014-07-07T15:49:52.783Z
Answers.LastEditDate: 2017-04-13T12:50:59.930Z
Answers.UserDisplayName: Victor
Body: <p>I have read through the <a href="http://buildwithcraft.com/docs/templating/tags#paginate" rel="nofollow">docs</a> and I am not sure if what I need to do is possible with array sets. I have filtered my entries using the following code"</p>
  
  <pre class="lang-twig prettyprint-override"><code>{% set allDatabytes = craft.entries.section('databytes').limit(null) %}
  {% set seriesCollection = [] %}
  
  {% for databyte in allDatabytes %}
  
    {# get only the series databytes #}
    {% set series = databyte.series %}
  
    {# add the series databytes to the series collection #}
    {% for entry in series %}
      {% set seriesCollection = seriesCollection|merge([entry.title]) %}
    {% endfor %}
  
  {% endfor %}
  
  {# Output the filtered results #}
  
  {% set filteredDatabytes = allDatabytes|without(seriesCollection) %}
  &lt;ul&gt;
    {% for entry in filteredDatabytes %}
      &lt;li&gt;{{ entry.title }}&lt;/li&gt;
    {% endfor %}
  &lt;/ul&gt;
  </code></pre>
  
  <p>What I now need to do is add pagination to the <code>filteredDatabytes</code> set of content.</p>
  
  <p><strong>From The Example Below</strong></p>
  
  <p>This is my code which currently doesn't display any results. I guess you add the limit to the <code>MyCriteria</code> model (is that the correct term)?</p>
  
  <pre class="lang-twig prettyprint-override"><code>{% set MyCriteria = craft.entries.section('databytes').series(':empty:').limit(10) %}
  
  {% paginate MyCriteria as entries %}
      {% for entry in entries %}
          {{ entry.title }}
      {% endfor %}
  
      {% if paginate.prevUrl %}
          &lt;a href="{{ paginate.prevUrl }}"&gt;Previous Page&lt;/a&gt;
      {% endif %}
  
      {% if paginate.nextUrl %}
          &lt;a href="{{ paginate.nextUrl }}"&gt;Next Page&lt;/a&gt;
      {% endif %}
  {% endpaginate %}
  </code></pre>
  
Tags: <pagination>
Title: Paginate An Array Of Entries
ThreadText: # Paginate An Array Of Entries
  
  (Asked by: username_0 on 2014-07-07)
  
  I have read through the [docs](http://buildwithcraft.com/docs/templating/tags#paginate) and I am not sure if what I need to do is possible with array sets. I have filtered my entries using the following code"
  
  ```twig
  {% set allDatabytes = craft.entries.section('databytes').limit(null) %}
  {% set seriesCollection = [] %}
  
  {% for databyte in allDatabytes %}
  
    {# get only the series databytes #}
    {% set series = databyte.series %}
  
    {# add the series databytes to the series collection #}
    {% for entry in series %}
      {% set seriesCollection = seriesCollection|merge([entry.title]) %}
    {% endfor %}
  
  {% endfor %}
  
  {# Output the filtered results #}
  
  {% set filteredDatabytes = allDatabytes|without(seriesCollection) %}
  <ul>
    {% for entry in filteredDatabytes %}
      <li>{{ entry.title }}</li>
    {% endfor %}
  </ul>
  
  ```
  
  What I now need to do is add pagination to the `filteredDatabytes` set of content.
  
  **From The Example Below**
  
  This is my code which currently doesn't display any results. I guess you add the limit to the `MyCriteria` model (is that the correct term)?
  
  ```twig
  {% set MyCriteria = craft.entries.section('databytes').series(':empty:').limit(10) %}
  
  {% paginate MyCriteria as entries %}
      {% for entry in entries %}
          {{ entry.title }}
      {% endfor %}
  
      {% if paginate.prevUrl %}
          <a href="{{ paginate.prevUrl }}">Previous Page</a>
      {% endif %}
  
      {% if paginate.nextUrl %}
          <a href="{{ paginate.nextUrl }}">Next Page</a>
      {% endif %}
  {% endpaginate %}
  
  ```
  
  **Tags:** pagination
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2014-07-08. Score: 3 | Accepted answer
  
  As [username_2 rightfully points out](https://craftcms.stackexchange.com/a/782/57), the {% paginate %} tags require an ElementCriteriaModel, so you can't do what you're doing in your first example because as soon as you call:
  
  ```
  {% for databyte in allDatabytes %}
  
  ```
  
  Craft hits the database and converts the ElementCriteriaModel into actual EntryModels.
  
  We also don't have support, yet, for passing `:empty:` into things like AssetFields, TagFields, etc., which is why your second example won't work... however that is on our list to add!
  
  In this case, I think your best bet is going to be to do through the search service with something like this:
  
  ```
  {# Search for 10 entries in the 'databytes' section where the 'series' assetField doesn't have anything selected. #}
  {% set myCriteria = craft.entries.section('databytes').search('-series:*').limit(10) %}
  
  {% paginate myCriteria as entries %}
      {% for entry in entries %}
          {{ entry.title }}
      {% endfor %}
  
      {% if paginate.prevUrl %}
          <a href="{{ paginate.prevUrl }}">Previous Page</a>
      {% endif %}
  
      {% if paginate.nextUrl %}
          <a href="{{ paginate.nextUrl }}">Next Page</a>
      {% endif %}
  {% endpaginate %}
  
  ```
  
  > **Comments:**
  > **username_0**: Hi username_1, thank you that worked great. Its good to see there is so many different ways to attack a problem.  
  
  ---
  
  ### Answer by username_2 on 2014-07-07. Score: 1
  
  This won't work with your example, because the [pagination-tag](http://buildwithcraft.com/docs/templating/tags#paginate) only accepts an [ElementCriteriaModel](http://buildwithcraft.com/docs/templating/elementcriteriamodel), not an array of already fetched entries:
  
  ```twig
  {% paginate MyCriteria as PageSubset %}
  
  ```
  
  See also: [What are the differences between an elementCriteriaModel and fetched elements?](https://craftcms.stackexchange.com/q/265/177)
  
  ---
  
  If I understand your code correctly, you want to get all entries which have an empty `series`-field?
  
  If so, you don't have to fetch all entries and check against it, you can just add this to the [ElementCriteriaModel](http://buildwithcraft.com/docs/templating/elementcriteriamodel):
  
  ```twig
  {% set MyCriteria = craft.entries.section('databytes').series(':empty:') %}
  
  {% paginate MyCriteria as entries %}
  ....
  {% endpaginate %}
  
  ```
  
  ---
  
  **Why does the pagination tag need a CriteriaModel?**
  
  An ElementCriteriaModel can be compared to a sql query, it specifies what elements/entries to fetch (it sets the criteria). If you [treat your CriteriaModel as an array or append .first()](http://buildwithcraft.com/docs/templating/elementcriteriamodel#outputting-elements) it will fetch those entries and replace the results with the CriteriaModel.
  
  The [pagination-tag](http://buildwithcraft.com/docs/templating/tags#paginate) needs a CriteriaModel (or "query") because it adds an offset (to the "query") depending on what page you are on, and then fetches the entries. - That's why the pagination-tag doesn't work with already fetched entries.
  
  > **Comments:**
  > **username_0**: Hi username_2, thank you, that looks like just the solution I am after. I spent ages trying to figure out what I came up with to. Sorry but how Craft works with ElementCriteriaModels is till very confusing to me and I have read the docs and Stuarts post a few times. Could you expand on your example as the only pagination example I have is http://buildwithcraft.com/docs/templating/tags#paginate and I can't figure what to add to your solution to make it work. Many thanks for your help.  
  > **username_2**: I added an explanation for the CriteriaModel. Copying the example pagination-code from the docs inside my example should work fine, what problems do you have exactly?  
  > **username_0**: Hi username_2, thank you for the explanation and I have updated my example to show you what I have which currently displays no results.  
  > **username_2**: I tested your code and it worked in my test. What field type is `series` and what does it contain?  
  > **username_0**: `series` is an entries field type: http://buildwithcraft.com/docs/entries-fields and can contain multiple related entries.  
  > **username_2**: Can you remove `.series(':empty:')` to check if all entries are fetched. If so, can you make sure that there is an entry where the `series` field is empty.  
  > **username_0**: Let us [continue this discussion in chat](http://chat.stackexchange.com/rooms/15587/discussion-between-username_0-redfern-and-username_2-in).  
  
  ---
  
  