Skip to content

Wrapping a dom child in a template #19

@IamSAB

Description

@IamSAB

I want to wrap a child element of a site with an template.

$dom = new Dom;
$dom->load('site.html');
foreach($dom->find('node') as $node) {
   $tmpl = new Dom;
   $tmpl->load('template.html');
   $tmpl->find('*[id=container])[0]->addChild($node)
   $node->getParent()->replaceChild($node->id(),$tmpl->root);
}

However I think (even if the replaceChild method works) the output will not be as expected. We add $node as child to the root of $tmpl. But what happens, when I replace $node with $tmpl?

Will $node, as child of $tmpl also get deleted? I am thinking about what is passed by value or reference and PHP handles that often very unclear ...

For wrapping also a custom function could be considered, if the above question answers with yes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions