Jump to content

Set repeater field from different page via api


androbey
 Share

Recommended Posts

Hi everyone, 

I have problems once again. This time it's about setting a certain field of a repeater item from a different page. 

This is what I have so far: 

I create a new repeater item on Page A via api using following code:

// template of page A
$item = $page->repeater_field->getNewItem();
//set content to fields..
$item->save();
$item_id = $item->id;
//returns e.g. for $item_id = 1222

Now the goal is to set a field of that particular repeater item from Page B. But I am not able to get to the particular repater item to set a field. 

 

// template of page B
$ref = $pages->get($page->page_a_reference->id);

//With following code I get the repeater field items, but I cannot access (or determine) the repeater item I would like to get (with ID 1222).
$rep = $ref->repeater_field;

//Following code returns null
//$rep = $ref->get(1222);


What do I do wrong, or better asked, how can I set a field of a repeater item from different page?

Link to comment
Share on other sites

Try:

$rep = $ref->repeater_field->get(1222);

It should get the you the repeater item with ID 1222. This is a RepeaterPage which is pretty much a normal Page object. 

I don't have very clear how you know which repeater item you want to edit and where are you getting the data that is meant to be set on the repeater items.

Every repeater field is an array of pages, where you can also use the find/get methods to match pages through selectors. Also, every repeater Item can have it's fields set and saved pretty much the same as normal pages. 

  • Like 2
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...