Jump to content

how do i address a field with multiples images, that is in another page?

Recommended Posts

Hello ppl

I'm trying to create an image banner to show in all pages of the site, and for this i created a page to hold multiple images in a field (latter im gonna deal with animating them). The page is published, So this is the tree of values i got:


i can address the page with

$pg_settings = $pages->get('name=settings');

it seem to be correct because print_r gets me a biiiig array if info

now the problem is getting the array of images, with their respective url's. I tried:

$pg_settings = $pages->get('name=settings');
// echo "<br />pg_settings: " . print_r($pg_settings->get("banners_slideshow")); // seems ok...

$imgs = $pg_settings->get("banners_slideshow");
print_r($imgs[0]->get("url")); // i got nothing??

In this page i also have a non repeatable image field for the logo, so i think i cant use the images array from that page. 

the question remains: how do i address a field with multiples images, that is in another page?

thanks for the patience!

Share this post

Link to post
Share on other sites

i also dont get why both print_r's show the same result 

$pg_settings = $pages->get('name=settings')

$imgs = $pg_settings->get("banners_slideshow");

Share this post

Link to post
Share on other sites

If you access the field you get a WireArray of image objects, and each has a method url (I think), it's not a property or a field.

$imgs = $pg_settings->get("banners_slideshow");
$imgs->first()->url; // the first
$img->eq(0)->url; // etc

foreach($imgs as $img) echo $img->url;

Forget about print_r() on arrays and object, you won't get useful infos most of the time it's overkill.

Maybe have a deep read here http://processwire.com/api/fieldtypes/images/

  • Like 2

Share this post

Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Spyros
      I'm having a strange issue with the $page->find(), for some reason I'm missing some of the pages from the results. I found then that I was missing all the pages with the same "PAGE NAME". Is it a bug or am I missing something?
      If I change the "PAGE NAME" of one of the missing ones then I'm retrieving the page without any problem.
      Thank you
    • By fruid
      this is the first time I'm using ProcessWire.
      I thought I get how fields, template and pages work, but when I create a template in the CMS, it doesn't generate any file in site/templates/
      Then I thought I might need to create a blank file myself manually on the FTP (which already seems odd to me).
      Once I did that, I tried to add fields to the template but again, doesn't write to the php file.
      When I create a new page and apply said template to it, the page stay blank.
      AFAIK the mod_rewrite of the apache is on and I went for the worst case scenario described here https://processwire.com/docs/security/file-permissions/ and set all file-permissions for future files to 0666 and folders to 0777 in the config.php
      What am I not getting and what am I doing wrong?
      Help is appreciated, stay save everybody,
    • By benbyf
      Hi, Looking to create form elements on a page–some input with a colection of form inputs and the appropriate labels and variables for that input. I've used ProForms in the past and rolled out my own when creating simply one off forms, but I wonder if anyone has found a good way of allowing form creation on page editing so that clients can adhocly make and edit forms?
    • By EyeDentify
      Hello Dear PW Gurus.

      Hope you fair well in these Corona Crisis times.

      Anyhow, i have a problem with a Cryptic error message that shows up when i am trying to Delete images out of a Images field.
      The Error message does say a little but it does not make sense to me why i can´t delete the images because of it.

      Is it some permission issue perhaps?

      I will attach screenshots of it and what i did prior to it.
      I am from sweden so ignore the funny words here and there.

      Hope you all can send me on the right track.
      i am running PW 3.0.139 on this install.


      Step 2: Select the images with the trashcan symbol

      Step 3: Cryptic Error message

      I am scratching my head on this one, have not seen this before.

      Thankfull for all help.
  • Create New...