I have a Structure section (galeriesPhotos) with two Entry Types:

  • Albums - the categories on the index.html page
  • Photos - the the actual gallery on the entry.html

I'm trying to display the images related to the "Albums" on entry.html like this:

{% set entries = craft.entries.section('galeriesPhotos').getEntryType('Photos') %}

{% for image in entries %}
  <img src="{{ image.getUrl }}">
{% endfor %}

Nothing happens. I get a blank page without any errors. What I am doing wrong?

  • I think the for loop is incorrect, try changing {% for image in entries %} to {% for entry in entries %} and then change the img src to {{ entry.image.first().url }} Also if you switch on dev mode in the config it will help debug your templates. Jan 16, 2015 at 9:53
  • Just tried that and it's not working
    – jjem
    Jan 16, 2015 at 9:55
  • It actually gives only the path to where the images are (<img src="example.com/gallery/2014/friday/") instead of the actual images that are uploaded in structure... Your suggestions give an error. Sorry
    – jjem
    Jan 16, 2015 at 10:02
  • Impossible to access an attribute ("url") on a NULL variable ("")
    – jjem
    Jan 16, 2015 at 10:13
  • 1
    Well done. Suggest you post your working code as an answer and tidy up the comments. Jan 16, 2015 at 12:32

1 Answer 1


In the example code above, the query is retrieving a list of Entries and setting it to the variable entries. Then, you are trying to loop through those Entries and treat them like they are a list of Assets.

As noted in the comments, this was complicating the situation.

It appears that, on the entry.html page, the entry variable was already available, as Craft makes that entry variable to all individual entry pages in Sections that have URLs.

This makes accessing the Assets field on that page as simple as accessing a field, rather than needing to create a separate query to find the data. From the comments above, the solution was to just access the appropriate Assets field on the Entry Page template and loop through them:

{% for asset in entry.entryFieldHandle %}
    <img src="{{ asset.url }}">
{% endfor %}

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.