Jump to content

Return all page images as array


floridaDev
 Share

Recommended Posts

I have a particular template that has 10 text fields and 10 images. The goal is that whichever text is inserted into text field #1 it'll display underneath image #1. I'm having trouble retrieving the images for that page as an array. I've tried

var_dump($page->images)

and the output is the pages entire fieldset..not just only images. 

Link to comment
Share on other sites

5 hours ago, floridaDev said:

and the output is the pages entire fieldset..not just only images.

That's odd - I don't see how that can happen.

An images field will return an array of images (a 'Pageimages' WireArray) if you have chosen that in the field settings.

2016-11-26_103329.png

 

5 hours ago, floridaDev said:

I have a particular template that has 10 text fields and 10 images. The goal is that whichever text is inserted into text field #1 it'll display underneath image #1.

This approach is okay, but if it were my project I think I'd find that a bit awkward. Hard for editors to make a clear connection between which text field goes with which image. And 10 identical fields seems like something to avoid where possible (maintenance would be a pain for a start). Suggestions...

If the text field only needs a normal text input then use the Description field for each image.

If the text field needs to be a textarea then try the Image Extra module.

If the text field needs to be a CKEditor field then consider creating a Repeater containing an image field limited to 1 image and the CKEditor field. Then you can fix the Repeater to 10 items using Limit Repeater (shameless self-promotion :D)

  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...