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 %}
Lindsey D
  • 23,974
  • 5
  • 53
  • 110
matthew
  • 333
  • 2
  • 8
  • 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 Aug 30 '16 at 05: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 Aug 30 '16 at 05:59
  • I have just included the output of when i do a dump on program.featureImage – matthew Aug 30 '16 at 06:05
  • What does {{ program.featureImage.first.filename }} output? – Fyrebase Aug 30 '16 at 06:09
  • When I try that i get the following error Impossible to access an attribute ("filename") on a null variable – matthew Aug 30 '16 at 06:31
  • By all accounts, that code should be working. Have you tried using a different image? – Fyrebase Aug 30 '16 at 06:43
  • Yep i have tried a couple of images now just to be sure, I have no idea why it wouldnt display the url – matthew Aug 30 '16 at 06:47
  • It's a tough one to figure out with out getting into your code first hand :( – Fyrebase Aug 30 '16 at 11:14
  • @matthew Do you get an error or just no URL output? i.e. <img src="" And are you testing with devMode enabled? – Brad Bell Aug 30 '16 at 20:05
  • No error but I have posted an answer to this issue and has been resolved thanks for your help @fyrebase and Brad – matthew Aug 30 '16 at 22:50

1 Answers1

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

matthew
  • 333
  • 2
  • 8