Jump to content

Find page name for a repeater item


zyON
 Share

Recommended Posts

On this topic:  I've asked (and answered myself) how to get the field name on a page used for uploading files. 

Now, what if I'm using a repeater field to upload files? How can I get the name of the page of the item uploaded to?

I'm using a InputfieldFile::fileAdded hook and even if I try to get the $event->arguments(0)->page->name I get the internal name of the repeater page, not the name of the page where the field is. $event->arguments(0)->page->parent->name is almost what I need because I get the name "for-page-xxxx" and xxxx is the id of the page where the field belongs. 

Is there any easier way to reference this page name without, I don't know, parse this string to extract the numeric id and then search for the page name?

Link to comment
Share on other sites

Well I think it's right how you did it with $event->arguments(0)->page->parent->name . It's the same solution as used here: https://processwire.com/talk/topic/2518-repeater-fields-via-api-it-has-no-parent-assigned/?p=24062

Maybe we can find a cleaner solution if you tell us a bit more about for what reason you need the parent page of the repeater and so on :)

Link to comment
Share on other sites

Nico,

I just wanted to know if there was a better way (through referencing?) than using: 

$p = $event->arguments(0)->page->parent->name;
$page = wire(pages)->get("name={$p}")->title;

to get the name of the page (not that there's anything wrong with that).

Ok, the reason I need the to upload a field with a repeater with file fields inside is because I need to add a description of those files that must be translated in 5 languages.  That was the fastest way I've found to achieve this.

  • Like 1
Link to comment
Share on other sites

interobang,

That's it. Thanks. 

this is all I need now: 

$p = $event->arguments(0)->page->getForpage()->title;

I know we have available the very useful cheatsheet provided by Soma but is there further documentation for the PW API other than that provided here

  • Like 1
Link to comment
Share on other sites

I know we have available the very useful cheatsheet provided by Soma but is there further documentation for the PW API other than that provided here

If I can't find it on the cheatsheet, I usually directly look into the well documented sourcecode or google search the forum here. 

Link to comment
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
 Share

×
×
  • Create New...