1

I am new to Craft CMS. I am building my first industrial design portfolio site and am facing a brick wall.. The problem is that I have three image handlers that I set up in field. thumbnail, projectBanner and projectThumbnail that I want to display in project section. I found this code snippet and made changes to it to match one of my image handler.

{% for asset in entry.projectBanner %}
    <img src="{{ asset.getUrl(thumb) }}" alt="{{ asset.title }}" />
{% endfor %}

I made sure that I have upload the image (projectBanner) to a entry and refreshed the browser. The image does not show up but the title does. Could anyone please tell me what I did wrong and what the correct method to achieve outputting images into entries?

3
  • 1
    @mcclaskiem: While related, I don't believe the thread is a duplicate. The OP may benefit greatly from reading the linked thread, however. – Lindsey D May 2 '16 at 23:10
  • @WilliamSpark: What is the value of thumb? Are you certain it's outputting a string containing one of the image transform handles you specified? – Lindsey D May 2 '16 at 23:11
  • @LindseyD ya that makes sense thats why I answered it and marked duplicate. Based on the question, it seems as though they are separate fields, could be wrong though. – mcclaskiem May 2 '16 at 23:51
7

When you are working with an asset field you are actually looking at the object so you need to call {{asset.url}} in order to actually output the path to the image or whatever asset you are working with.

{% for asset in entry.projectBanner %}

    <img src="{{asset.url}}>

{% endfor %}

As some additional information I would checkout eager-loading in craft as it can drastically help performance as your website grows!

https://craftcms.com/docs/templating/eager-loading-elements

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