2

I am trying to create a portfolio site. I have set up field for image, description and a link.

The description and link are being pulled through but the image is not working. This is what I have for the images field:

{% for assets in entry.image %}
    <img class="portfolio-images" src="{{ asset.url }}">
{% endfor %}

This is the full entry:

<section class="portfolio-section" id="portfolio"> 
    <h2 id="opaque" style="color:white;">Here are a few of the projects I have been working on recently.</h2>
    <ul class="portfolio Grid">

        {% for entry in craft.entries.section('portfolio').limit(9) %}
            <li class="portfolio-item Grid-item Grid-third">
                <div class="portfolio-info">
                    <h3 class="portfolio-title">{{entry.title}}</h3>

                    {% for assets in entry.image %}
                        <img class="portfolio-images" src="{{ asset.url }}">
                    {% endfor %}

                    {{entry.description}}
                </div>

                <a href="{{entry.website_link}}" target="_blank"><button class="button" type="button">View website</button> </a>
            </li>
        {% endfor %}
    </ul>
</section>

Why is the text and link working but the image not?

Thanks!

5

You are looping through entry.image with the key assets but inside your loop you are trying to access the URL on asset. These need to be the same.

{% for asset in entry.image %}
  <img class="portfolio-images" src="{{ asset.url }}">
{% endfor %}
| improve this answer | |
  • Have have tired various versions/combinations with no luck. What is the correct code please? – DIB Aug 17 '16 at 12:05
  • Have you checked the fieldname is correct? Try adding {{ entry.image|length }} to your template and see what the result is. – Luke Pearce Aug 17 '16 at 12:15
  • Hi Luke, Thanks but I tried that and still no luck. The field name is correct. I'll try adding | length and see how I get on. – DIB Aug 17 '16 at 12:57
  • Do you have devMode on? Luke's answer should've done the trick unless the field name is incorrect or there is no asset. – AbbeyDesign Aug 17 '16 at 13:01
  • When I add {{ entry.image | length }} I get 1 displayed on the page. Sorry I very new to this. – DIB Aug 17 '16 at 13:07

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.