Jump to content

Recommended Posts

Posted

Hi there,

Wonder whether someone can explain something I'm seeing.

I started out with an image field type - no repeater. I could access an individual image object reference, point to it's "url" property and I had a path to the image.

When the image field is in the repeater, I see the following value:

$repeater->images->url = /ProcessWire/site/assets/files/1009/

When I look in this folder, I see the image that I want, and also, another image that in this case is called "gina-bg-2.0x100.jpg" - the one I actually added was "gina-bg-2.jpg". So, firstly, I don't know where the x100 version of the image has come from?

Secondly, I want to get the full url path to gina-bg-2.jpg but I cannot seem to see a way of directly referencing it now the image is inside the repeater?

$repeater->images is a "Pageimages" type reference. How can I access each contained Pageimage?

If I specify $image->images[0], I get a "Page" type and not the Pageimage that I expect.

Any ideas appreciated! :)

Thanks

--Gary

Posted

You need to do.

$page->reapeatname->imagename->url;

Sorry maybe you already did?

Also the x100 image is most surely from the thumbnail in the admin.

Edit:

If it's a multiple images field you have to iterate them or using $array->first()->url; it's in a array.

$repeater->images->first()->url

should then give the first image.

  • Like 1
Posted

First of all, 0x100 version is a thumbnail created by either size(), width() or height() calls in your templates or possibly by admin (if you've chosen to show thumbnails for that image field.)

Secondly, I'm assuming that your image field is called "images" and it can contain multiple images? It sounds like you're asking the field itself for an URL when you should be asking that from an individual image:

echo $repeater->images->eq(0)->url;

Or you could loop through all the images:

foreach ($repeater->images as $image) {
echo $image->url . "<br />";
}

Edit: Soma was faster -- again :)

  • Like 3
Posted

Teppo is way too slow, always second ;)

FORUM PROTIP that I spied from Soma: quickly post something, then edit it few times. You'll win every time!

  • Like 8
Posted

I'm not sure, but are you copying the answers as well from the later posters? First quick draft with total nonsense, then Teppo (or some other poor fellow) comes with careful examples... some copy & paste magic (with few edits of course) and voila! And final nail in the coffin is that "Sorry dude, I was first here" ;)

  • Like 1
Posted

No, I'm reading too quick and post something, then read again, edit it again lol I'm not copying the next. I should know, sorry it happened few times already and I need to hold me back a little.. oink

Posted

@teppo & @soma - thank you both!

This is exactly what I was looking for. I thought $repeater->images[0] (using an indexer in the images collection) would give me what I wanted but instead, it gives a Page type which doesn't make too much sense to me although doubtless, there will be a good reason for it doing so!

This is so awesome! Thanks for the brilliant replies :D

--Gary

Posted

Hi there,

Wonder whether someone can explain something I'm seeing.

..

I guess in the xcode debugger...? :P (will stop it now)

Posted

I said can "someone" explain - the debugger doesn't qualify!

Keep 'em coming - there's a lot of mileage left in the debugger wise-cracks ;)

Posted

This is exactly what I was looking for. I thought $repeater->images[0] (using an indexer in the images collection) would give me what I wanted but instead, it gives a Page type which doesn't make too much sense to me although doubtless, there will be a good reason for it doing so!

--Gary

A type page for a image? My bet would be that you see the repeater "page" as they're done as stored hidden pages in the admin branch.

Posted
I thought $repeater->images[0] (using an indexer in the images collection) would give me what I wanted but instead, it gives a Page type which doesn't make too much sense to me

I'm not sure why you'd be getting a Page by accessing that, I would think it should be null. What do you see from get_class($repeater->images)?

However, I want to mention that Pagefiles/Pageimages aren't indexed by number, they are indexed by filename, so am thinking at the moment that $images[0] may not relate to anything. $repeater->images->eq(0) is probably what you were after, or $repeater->images->first().

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
×
×
  • Create New...