Jump to content
Tom.

Get index of repeater

Recommended Posts

Confusing one, $page->index() works, but in a repeater item, looping through them and getting $item->index() returns fatal error too few arguments passed. It's using WireArray index rather than PageArray index. It's the first time I've come across this, and it's the first time I've seen an inconsistency in the API. You would imagine that both return an index value if empty. But I always thought a repeater returned a PageArray anyway? 

It might be worth I'm using the render method, so I'm unsure whether that makes it come through as a WireArray? either way, anyone know how to get the item index for a WireArray?

Share this post


Link to post
Share on other sites

Repeater items should be stored in a RepeaterPageArray, which in turn extends PageArray, so this does indeed sound strange. Would need to peek into some code to say anything more, and I'm not entirely sure what "the render method" exactly means here 🙂

Share this post


Link to post
Share on other sites

I got curious and debugged into this because I ran into a similar issue with prev() method while rendering a repeater matrix field, and had to include the 'check_access=0' selector to actually find a prev() page while a guest user visited the page, though I'm not being able to to this with index() too, like:

$page->index('check_access=0');

Maybe you can try it and see if it works for you?

  • Like 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...