4

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 %}
  • 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 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 Aug 30 '16 at 5:59
  • I have just included the output of when i do a dump on program.featureImage – matthew Aug 30 '16 at 6:05
  • What does {{ program.featureImage.first.filename }} output? – Fyrebase Aug 30 '16 at 6: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 6:31
13

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, privacy policy and cookie policy

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