5

After going through the documentation I believe that this is the correct code to output the url for the asset field but its not working and I have no idea why. Please help!

{% nav program in craft.entries.section('program').level(1) %}
  {% set active = entry is defined and program.isAncestorOf(entry) %}

  <div class="{% if active %}active{% endif %}">
      {% if program.featureImage|length %}
        <img src="{{ program.featureImage.first().url }}" alt="{{ program }}">
      {% endif %}
      <h3 href="{{ program.url }}">{{ program.title }}</h3>
      <p>{{ program.description }}</p>
  </div>

{% endnav %}
10
  • That looks correct. Are the other variables such as program.url and program.title working? What value do you get when outputting program.featureImage|length?
    – Fyrebase
    Commented Aug 30, 2016 at 5:46
  • program.url and program.title are both working as intended they output the correct data. I get a value of 1 when outputting program.featureImage|length by itself. Its a really wierd cause everything indicates that it should just output the image url
    – Matthew
    Commented Aug 30, 2016 at 5:59
  • I have just included the output of when i do a dump on program.featureImage
    – Matthew
    Commented Aug 30, 2016 at 6:05
  • What does {{ program.featureImage.first.filename }} output?
    – Fyrebase
    Commented Aug 30, 2016 at 6:09
  • When I try that i get the following error Impossible to access an attribute ("filename") on a null variable
    – Matthew
    Commented Aug 30, 2016 at 6:31

1 Answer 1

17

So after looking through other craft websites to see how they where able to get images to work I discovered what I did wrong when setting up the asset source. The thing is though that the craft documentation is not very helpful in this regard, also there are no errors or helpful output to indicate that my configuration might be the issue.

What I needed to do

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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