I am on my first Craft CMS test site. Have some problems showing a simple image.

<img src="{{ entry.hero.first().url }}" title="{{ hero.title }}">

I get the title but can't get the URL. The src attr is always empty. Tried a couple of variants like:

  • entry.hero.first().url()
  • entry.hero.first().getUrl()
  • with and without ()
  • etc.

But entry.hero.first().filename gives me "my_testfile01.jpg"

I can't see what is wrong.

File is local with path set to "./" Image field has no sub path.

MAMP (Apache + PHP 7)


By the way, is your Craft CMS version 3.x? If so, using "one" is recommended instead of "first", which is deprecated.

  • Yes, I tried that too. Nothing seems to work to get the file path
    – Fritko
    Sep 22 '20 at 9:25

Is the "Assets in this volume have public URLs" turned on?

  • It wasn't before. But I found it a little later and turned it on. Still frontend won't show the image nor an error. Noticed thumbnails in CP show, but if I click to preview it, the image is 404.
    – Fritko
    Sep 11 '20 at 12:11
  • Maybe you defined wrong path in volume - what is there? What is the path that errors out 404? Sep 16 '20 at 13:06
  • I guess not, because getting the filename works. There must be something wrong with the output
    – Fritko
    Sep 22 '20 at 9:25
  • What have you set as base URL for the volume? Sep 23 '20 at 10:55

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.