<p>This is a misunderstanding of the difference between an ElementCriteria model and actual fetched elements.</p>

<p>Some useful background reading: </p>

<p><a href="https://craftcms.com/docs/templating/elementcriteriamodel" rel="nofollow">https://craftcms.com/docs/templating/elementcriteriamodel</a></p>

<p><a href="https://craftcms.stackexchange.com/questions/265/what-are-the-differences-between-an-elementcriteriamodel-and-fetched-elements">What are the differences between an elementCriteriaModel and fetched elements?</a></p>

<p>You could do what you're looking for using Twig's <a href="http://twig.sensiolabs.org/doc/functions/random.html" rel="nofollow">random</a> method:</p>

<pre><code>{% set projectImg = craft.entries.section('projekte').find() %}
{% set projectImages = [] %}

{% for item in projectImg %}
    {% set currentImage = item.bild %}
    {% set projectImages = projectImages | merge(currentImage) %}
{% endfor %}

{# Grab 3 random images from the array #}
{% for counter in 0..2 %}
    {% set asset = random(projectImages) %}

    &lt;img src="{{ asset.url }}"&gt;
{% endfor %}
</code></pre>

CC BY-SA 3.0
2016-10-17T17:37:36.503Z
2016-10-17T17:37:36.503Z
Brad Bell
<p>I want to get all images from the section <code>projekte</code> which are bound to the asset field <code>bild</code> I then want to fiddle around with <code>.limit()</code> and maybe <code>random</code> filters.</p>

<p>So I grabbed all images like described <a href="https://craftcms.stackexchange.com/questions/12152/how-to-grab-all-images-from-and-section">here</a></p>

<p>This works but as soon as I add <code>.limit()</code></p>

<pre><code>{% set projectImg = craft.entries.section('projekte').find() %}
{% set projectImages = [] %}

{% for item in projectImg %}
  {% set currentImage = item.bild %}
  {% set projectImages = projectImages | merge(currentImage) %}
{% endfor %}

{% for asset in projectImages.limit(3) %}
   &lt;img src="{{ asset.url }}"&gt;
{% endfor %}
</code></pre>

<p>This results in </p>

<blockquote>
  <p>PHP Notice: Array to string conversion</p>
</blockquote>

<p>Why can't I just ad whatever filter I want on that new loop now?</p>

<assets><filter><loop><assetfilemodel>
Get all images from a section
# Get all images from a section

(Asked by: username_0 on 2016-10-17)

I want to get all images from the section projekte which are bound to the asset field bild I then want to fiddle around with .limit() and maybe random filters.
So I grabbed all images like described here
This works but as soon as I add .limit()
{% set projectImg = craft.entries.section('projekte').find() %}
{% set projectImages = [] %}

{% for item in projectImg %}
  {% set currentImage = item.bild %}
  {% set projectImages = projectImages | merge(currentImage) %}
{% endfor %}

{% for asset in projectImages.limit(3) %}
   
{% endfor %}

This results in 

PHP Notice: Array to string conversion

Why can't I just ad whatever filter I want on that new loop now?

**Tags:** assets, filter, loop, assetfilemodel


---

## 1 answers

### Answer by username_1 on 2016-10-17. Score: 0 | Accepted answer

This is a misunderstanding of the difference between an ElementCriteria model and actual fetched elements.
Some useful background reading: 
https://craftcms.com/docs/templating/elementcriteriamodel
What are the differences between an elementCriteriaModel and fetched elements?
You could do what you're looking for using Twig's random method:
{% set projectImg = craft.entries.section('projekte').find() %}
{% set projectImages = [] %}

{% for item in projectImg %}
    {% set currentImage = item.bild %}
    {% set projectImages = projectImages | merge(currentImage) %}
{% endfor %}

{# Grab 3 random images from the array #}
{% for counter in 0..2 %}
    {% set asset = random(projectImages) %}

    
{% endfor %}


---

