1

I am sure this must be answered somewhere and I cannot find it. I need to grab all images from a section (channel) and display them in a slide show on the index page (index page is a single,so index page of the entries from that section). I just cannot seem to get this correct. Here is what I am trying

 {% set storyItem = craft.entries.section('stories').find() %}

so stories is the section where the entries are.

Then

{% for previewImage in storyItem.slideshowImage.offset(1) %} 
 ...
{% for previewImage in storyItem.slideshowImage.limit(1) %} 
...
{% for previewImage in storyItem.slideshowImage.offset(1) %}  

The limit and offset are just to make the slider I have work and that does work on another page so that does not seem to be what is stopping me here. I am somewhat new to craft and my gut is telling me this is a simple answer but I have been stuck on it for a while now and coming back to it off and on to no avail.

2
  • Just to be clear, is this a Single section? Otherwise, you want to grab every image from every field from every entry/entrytype in a section?
    – Brad Bell
    Commented Oct 28, 2015 at 20:41
  • So the section I want to grab from is a channel (stories), and I am trying to display them on a single, which displays all entries for that channel further down the page. I hope I am explaining that clearly, I think what I am trying to do is the second part of you question, grab all from that section. Commented Oct 28, 2015 at 20:43

1 Answer 1

3

I need to grab all images from a section and display them in a slide show on the index page.

You'll need to:

  1. Loop through all of your story entries.
  2. Grab the image from each story.
  3. Compile those into a Twig array.
  4. Create your slideshow as needed.

Here's how that all ties together...

{% set storyItems = craft.entries.section('stories').find() %}

{% set previewImages = [] %}

{% for item in storyItems %}
    {% set currentImage = item.slideshowImage.first() %}
    {% set previewImages = previewImages | merge(currentImage) %}
{% endfor %}

{# RENDER YOUR SLIDESHOW FROM previewImages #}

You'll need to initialize the previewImages array before beginning the for loop... Loops in Twig have their own scope.

The limit and offset are just to make the slider I have work...

I'm not sure exactly what you're trying to do with the offset, but I'd recommend manipulating your images array in Twig (as opposed to fancy queries to target specific images).

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.