block.image.one() shows more than one image I'm sure I'm doing something wrong here, but I'm at a loss as to what. I'm using Craft 3. My travel entry has 7 fields, one of those being a matrix field. My matrix has two blocks, postText and postImage.

Here's the bit of code I'm working with:

{% for block in entry.mainPost.all() %}
  {% if block.type == "postImage" %}
    {% set image = block.image.one() %}
        {% if image %}
            &lt;img src="{{ image.getUrl('summaryImage')}}" alt=""&gt;
        {% endif %}
  {% endif %}
{% endfor %}


I have an entry that has two images in the Matrix field. When I load the page, both images load. The documentation states that using .one() "Returns the first matching element". I have to assume that I'm not understanding the ElementCriteriaModel or Assets or the way Matrix works or something.
Yes you're correct, one() will get the first matching element. However, in your code you're not asking for the first image block, but rather the first image from each image block (because each image field can have multiple images attached to it).

The structure is basically something like this:

entry          &lt;- 1. The entry
  mainPost     &lt;- 2. The matrix field
    postImage  &lt;- 3. The matrix field's block
      image    &lt;- 4. The field inside the matrix field's block


We want to get the first result from #3 but you're currently only asking for the first result from #4. (It is probably a good idea to also ask for the first result from #4 as well btw.)

I think something like the following would work in your case:

{% for block in entry.mainPost.type("postImage").limit(1).all() %}
  {% set image = block.image.one() %}
  {% if image %}
    &lt;img src="{{ image.getUrl('summaryImage')}}" alt=""&gt;
  {% endif %}
{% endfor %}


UPDATE: looks like you actually need to use limit() instead of one() when querying for the block.

UPDATE 2: tacked on the all() to fix the deprecation!