-
Notifications
You must be signed in to change notification settings - Fork 2
Copy an element
Benjamin Kaiser edited this page Apr 15, 2021
·
8 revisions
You can use the "copy()" method of the class to create a copy of an element (including its descendant elements) as the child element of a given element:
mixed copy ( integer $source , integer $target , [ integer $position = false] )
Type | Name | Description |
---|---|---|
integer | $source | The ID of an element to copy. Remember that the element will be copied together with all its descendant elements! |
integer | $target | The ID of an element which will become the copy's parent element. Use "0" to make the copy a topmost element. |
integer | $position | (Optional) The position the element will have among the target element's children elements. When target element is "0", this refers to the position the element will have among the topmost elements. The values are 0-based, meaning that if you want the element to be inserted as the first child of the target element, you have to use "0", if you want it to be second, use "1", and so on. If not given (or given as boolean FALSE), the element will be inserted as the last of the target element's children elements. |
Return: Returns the ID of the newly created copy, or FALSE on error.
// insert a topmost element
$element = $f3t->add(0, 'Main');
// add a child element
$child1 = $f3t->add($element, 'Child 1');
// add another child element
$child2 = $f3t->add($element, 'Child 2');
// create a copy of "Child 2" element and put it as "Child 1"'s child
$f3t->copy($child2, $child1);`