Jump to content


Photo

Repeater & Images

repeater images

  • Please log in to reply
14 replies to this topic

#1 Gazley

Gazley

    Sr. Member

  • Members
  • PipPipPipPip
  • 239 posts
  • 38

  • LocationManchester, UK

Posted 09 August 2012 - 02:58 PM

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

#2 Soma

Soma

    Hero Member

  • Moderators
  • 3,183 posts
  • 1733

  • LocationSH, Switzerland

Posted 09 August 2012 - 03:07 PM

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.

@somartist | modules created | support me, flattr my work flattr.com


#3 teppo

teppo

    Sr. Member

  • Members
  • PipPipPipPip
  • 385 posts
  • 374

  • LocationFinland

Posted 09 August 2012 - 03:10 PM

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 :)

tweets - code - modules


#4 Soma

Soma

    Hero Member

  • Moderators
  • 3,183 posts
  • 1733

  • LocationSH, Switzerland

Posted 09 August 2012 - 03:12 PM

Sorry teppo! :D

@somartist | modules created | support me, flattr my work flattr.com


#5 apeisa

apeisa

    Hero Member

  • Moderators
  • 2,517 posts
  • 842

  • LocationVihti, Finland

Posted 09 August 2012 - 03:18 PM

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!

#6 Soma

Soma

    Hero Member

  • Moderators
  • 3,183 posts
  • 1733

  • LocationSH, Switzerland

Posted 09 August 2012 - 03:27 PM

ROFL apeisa!!! You spoiled it :D

Almost felt from chair reading this

@somartist | modules created | support me, flattr my work flattr.com


#7 apeisa

apeisa

    Hero Member

  • Moderators
  • 2,517 posts
  • 842

  • LocationVihti, Finland

Posted 09 August 2012 - 03:32 PM

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" ;)

#8 Soma

Soma

    Hero Member

  • Moderators
  • 3,183 posts
  • 1733

  • LocationSH, Switzerland

Posted 09 August 2012 - 03:35 PM

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

@somartist | modules created | support me, flattr my work flattr.com


#9 apeisa

apeisa

    Hero Member

  • Moderators
  • 2,517 posts
  • 842

  • LocationVihti, Finland

Posted 09 August 2012 - 03:38 PM

I was joking of course (about the copying part - quick editing is still true) ;)

#10 Gazley

Gazley

    Sr. Member

  • Members
  • PipPipPipPip
  • 239 posts
  • 38

  • LocationManchester, UK

Posted 09 August 2012 - 04:51 PM

@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

#11 Soma

Soma

    Hero Member

  • Moderators
  • 3,183 posts
  • 1733

  • LocationSH, Switzerland

Posted 09 August 2012 - 05:06 PM

Hi there,

Wonder whether someone can explain something I'm seeing.
..


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

@somartist | modules created | support me, flattr my work flattr.com


#12 Gazley

Gazley

    Sr. Member

  • Members
  • PipPipPipPip
  • 239 posts
  • 38

  • LocationManchester, UK

Posted 09 August 2012 - 05:37 PM

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 ;)

#13 Soma

Soma

    Hero Member

  • Moderators
  • 3,183 posts
  • 1733

  • LocationSH, Switzerland

Posted 09 August 2012 - 05:47 PM

Sorry I actually meant "I guess you see..." ;)

@somartist | modules created | support me, flattr my work flattr.com


#14 Soma

Soma

    Hero Member

  • Moderators
  • 3,183 posts
  • 1733

  • LocationSH, Switzerland

Posted 09 August 2012 - 05:50 PM

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.

@somartist | modules created | support me, flattr my work flattr.com


#15 ryan

ryan

    Hero Member

  • Administrators
  • 5,753 posts
  • 3102

  • LocationAtlanta, GA

Posted 10 August 2012 - 07:06 AM

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().





Also tagged with one or more of these keywords: repeater, images

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users