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 skeltern
      WebP image support is great and works fine. But once created I've issues to get rid of all API generated WebP variations.
      The backend image field variations "Delete" works and I can remove all variations JPEG plus WebP. Image list is clean but all WebP API variations are still stored in file system (for instance files/12345/84.900x675.webp etc). I can only use ImageSizer with temp 'force' option to request fresh WebP variations or have to delete WebP files from folders. No other way so far. Tested with 2 sites and latest master PW 3.0.165.
      Is there somewhere a "magic button" or config/setup thing to solve my sticky WebP issue?
    • By psy
      I've searched, and maybe missed, the solution. I have a 'normal' images field and uploading images with a file size greater than 10Kb is fine. Any image size smaller results in the never-ending spinner and no upload.
      No min/max width/height set on image uploads in admin, ie just the defaults.
      Any ideas on how to fix?
      PW: 3.0.175
      PHP: 7.3
      Marking it as "Resolved" rather than "Solved" as it auto-magically fixed itself. No idea whether PW, PHP, or just an internet hiccough... All good now 🤞
    • By rjgamer
      is there a hook after the current (active) page got created? Or which method got called in the Page class after the Constructor of the current page got initialized?
    • By rjgamer
      Hi guys,
      the field "redirect_last" of type DateTime got not updated. The update on the field "redirect_counter" works and got saved.
      Does anybody know what I did wrong in my code?
      if ($input->urlSegment(1) === 'redirect') { $page->of(false); $page->redirect_last = time(); $page->redirect_counter += 1; if ($page->save('redirect_counter')) { $session->redirect($page->website_url, 302); } } Thanks.
    • By totoff
      Dear all,
      tomorrow I'll have to introduce some editors on how to upload and edit images in image fields in Processwire. The site in question is quite image rich and I've spent some time to serve the appropriate images via scrcset already cropped for different screen sizes.
      However, the backend offers a lot of possibilities to manipulate images and most of them I'm not familiar with because as a developer I've never spent much thinking on what all the features might be good for … Yet I'm concerned that my editors work on images in the backend may interfere with my optimization strategies in the templates.
      Is there a general rule of thumb what content editors should do or not do with images in order not to break srcset strategies etc.? Maybe there is already a source of information you could point me to?
      Your recommendations are much appreciated!
  • Create New...