Programmatically duplicate a page to a new position in sitetree if a custom attribute is assigned to it

Permalink
how the heck do I solve this scenario?

I need to create a function that copy a page to a new location in the sitetree if (and when) a custom attribute is assigned to it.

From the documentaiton I found this
$page->duplicate(Page $newParent)

But I haven't managed to crack the code
I have tried this, which didn't work
Loader::model('page'); //load in the page model
   $cobj = Page::getByID($cID);
   if ($cobj->getCollectionAttributeValue('clasps')) { 
   $parentOfNewPage = Page::getByPath('/collection/clasps');
   $newPage = $cobj->duplicate('?', $parentOfDuplicates);
    }
   ?>

Also I am a bit confused as to where I should actually insert a working example of the above code.

I would be very happy if any of you could spare some time to hint me in the right direction.

View Replies:
Remo replied on at Permalink Reply
Remo