0

I have a content type that has 2 fields on it:

  • image (multiple values)
  • image description (multiple values)

I have 6 images and 6 descriptions. I want to use a view to show each image with each description. I have tried playing around with the "Display all values in the same row" settings but just can't get this to work. It displays the same image repeatedly (6 times) and then the descriptions are all correct, then repeats the next image 6 times again.

I am tearing my hair out here, how do I get a view to simply out output:

Image 1, Description 1 Image 2, Description 2

and so on?

I have included an image of current output plus the way the fields were set up on the node. I have set them up this way as I need to import a lot of them.enter image description here

enter image description here

1
  • A small suggestion, it might better and easier to achieve this functionality using either Field Collection or Paragraph modules. Sep 30 '18 at 7:08
0

As already suggested the most sensible way would be to use the Alt text field for each Field value. You can still import the images with matching textual descriptions into a Single field with multiple images (each image with its own description).

But there is fix you can use if you want to keep the structure - "manually" add all the relevant information to display in Views results.

Multiple value Fields have delta info that records the order/placement of each value.

As you know in Views these types of Fields have Multiple field settings where you can Display all values in the same row.

This is what you want to do here, but only display one value at a time. First add the File field showing the first image only, then add Description field showing the first description only, then add File field again showing the second image, then add the Description field again showing the second description only and so on until you've shown all of them:

First image and Description:

File: Display 1 value(s) starting from 0 (first item is 0)
Description: Display 1 value(s) starting from 0 (first item is 0)

Second image and Description:

File: Display 1 value(s) starting from 1 (first item is 0)
Description: Display 1 value(s) starting from 1 (first item is 0)

Third image and Description:

File: Display 1 value(s) starting from 2 (first item is 0)
Description: Display 1 value(s) starting from 2 (first item is 0)

etc...

1
  • Yes, I did exactly this, and went through them all one by one. The reason I didn't use Field Collection, which to me is the most obvious, is because I build sites around feeds importer so I can upload all data through this. Field collections requires a second importer which is a pain. Oct 1 '18 at 3:05
0

As commented there might be better data models. But in case you can't change the data model it's probably the easiest solution to switch the View to display content in a view mode and display the field deltas in a node template:

node--content-type--view-mode.html.twig

{% for key, item in content.field_image if key|first != '#' %}

  {{ item }}

  {{ content.field_description[key] }}

{% 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.