First time working with Craft. I've got a Matrix field for team member profiles, title, name, image, etc.

I've got all the info pulled into the page but can't get the image. Here is my code, any help is appreciated!

{% for block in entry.teamMember %} 
    <figure class="team-item">
        <img src="{{ memberPhoto.url }}" alt="{{ block.memberName }}" />

        <figcaption class="team-item--info">
            <h3>{{ block.memberName }}</h3>
            <h4>{{ block.memberTitle }}</h4>
            <h5>hometown: {{ block.memberLocation }}</h5>
{% endfor %}

You need to loop through the assets as follows:

{% for asset in block.memberPhoto %}
    <img src="{{ asset.url }}" alt="{{ block.memberName }}" />
{% endfor %}

See https://craftcms.com/docs/assets-fields for more info.

  • 1
    Instead of a loop it's way better for your page performance to use the first method to get the first asset. Only use a loop if there's multiple images. – carlcs Jan 27 '16 at 19:09
  • Also see craftcms.stackexchange.com/questions/13401/… – carlcs Jan 27 '16 at 19:10
  • Ok great, Either one works. So I guess I will go with the first method for performance because there is only one photo per profile. Thanks! – Matthew Carleton Jan 27 '16 at 19:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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