1

I'm a newcomer to Craft from the far-off lands of WordPress. I hope my stay is long and fruitful, but at the moment that prospect is in danger. The problem I'm having must be embarrassingly simple, but I can't find my way through it.

The simple task I am attempting to accomplish it to display an image I uploaded to an entry via a new asset field.

If there is a method or practice for displaying an image via asset fields found on the internet, I have tried it. Currently, this is how I am trying to render the image in my twig file:

{% for image in entry.featuredImage %}
    <img src="{{ image.url }}" alt="blah">
{% endfor %}

No image shows up.

When I dump(image), should it be returning an array with 666 lines? I understand an asset returns a kind of Asset File Model (although I don't entirely understand what that means), but I find it hard to believe it's supposed to be that large.

Hoping to find at least the url of the asset, I perform dump(image.url), but it only returns bool(false). Why would it be doing that?

I created my uploads directory, and setup my asset source. I've tried doing this on an entirely fresh, up-to-date and clean install, but it still behaves the same way.

What am I missing or doing wrong?

Thank you!

4

I found the answer in a similar post here: Image asset url is not being output

My problem was with my Asset Source settings. Now that I think about it, it's obvious: I had no public URL declared for assets from my 'Uploads' source. Giving that a public url fixed the problem.

As I said, it's obvious now, but it'd be nice in the documentation could make even just a small reference to this.

0
{% set image = entry.featuredImage.first() %}
{% if image %}
    <img src="{{ image.url }}"/>
{% endif %}
  • Thank you for your answer. I have tried this already, and it behaves the same. When I search the object returned by dump(image) there is no url key to be found. I can successfully return {{ image.filename }}, but no url! – Steven Thate Aug 31 '16 at 16:34
  • For your answer to be as helpful as possible for the OP and others, it's always best to explain any code solutions and describe why the original code didn't work. – Luke Pearce Sep 1 '16 at 8:14

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.