salmiak Posted September 5, 2019 Share Posted September 5, 2019 What I'm trying to do in my template is the following. Get a specific page ($p) then(simplified): if($p->repeater_field->has("fieldA=$user")) { $p->a_page_reference_field->add($user); $p->of(false); $p->save(); } The code seems to work but it gives an exception: Can’t save page 9885: path for repeater page: Call $page->of(false); before getting/setting values that will be modified and saved. [fieldA] (in /wire/core/PagesEditor.php line 438) Can someone help me? Link to comment Share on other sites More sharing options...
wbmnfktr Posted September 5, 2019 Share Posted September 5, 2019 Have you tried removing $p->of(false) ? Otherwise have a look here: https://processwire.com/docs/fields/repeaters/ Repeater fields need to be initialized in order to accept a new item. At least it was necessary in the past. Maybe that's the case why it doesn't work. $building = $page->buildings->getNew(); // initialize - the important part $building->title = 'One Atlantic Center'; $building->feet_high = 880; $building->num_floors = 50; $building->year_built = 1997; $building->save(); $page->buildings->add($building); $page->save(); Link to comment Share on other sites More sharing options...
salmiak Posted September 5, 2019 Author Share Posted September 5, 2019 Ok so I changed it to something like: $rf = $p->repeater_field->get("fieldA=$user"); $rf->of(false); if($rf) { $p->a_page_reference_field->add($user); $p->of(false); $p->save(); } And now there is no exception. I seems strange to me that its neccesary to set of(false) on the repeater item/page when I'm not changing it. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now