I am using the Neo plugin in my project. I have made a Neofield article content with several block types in it. Amongst the block types that I have in it, is a gallery as well. Gallery block type has amatrix field imageWithCaption, and the field imageWithCaption has fields file which is the assets field, and fields imageTitle and caption which are plain text fields. I am able to display imageTitle and caption in my template but not a file, or the image itself. This is my template:

     {% for image in block.imageWithCaption %}
        <div class="large-4 columns">
          <div class="media-object stack-for-small">
            <div class="media-object-section">
                <img src="{{ image.file }}" alt="">
            <div class="media-object-section">
              <h6>{{ image.title }}</h6>
              <p>{{ image.caption }}</p>
      {% endfor %}

I get an error:

Object of class Craft\ElementCriteriaModel could not be converted to string

What I am doing wrong and how can I display the image?

1 Answer 1


It's tough to see the full context, just based on what you have here. From what I can tell, it seems like you might need to change <img src="{{ image.file }}" alt=""> to <img src="{{ image.file.first().url }}" alt="">.

Since the asset field can hold many assets, you have to declare .first() to grab the first one -- even if there's only one image. Then you have to grab the url property from the image, in order to get the correct src value.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.