I am trying to set up a template that will be a TWIG file using the DOM in PHP. So I set up the DOM and scrape the site I am getting the template from:
$dom = new DOMDocument('1.0');
$dom->loadHTMLFile('http://theurl.com');
then I modify the src of a script and save out the template:
foreach ($domNode->childNodes as $node) {
$node->setAttribute('src', "{{ asset('path/to/asset.js') }}");
}
$pageHtml = $dom->saveHTML();
$pageHtml is then saved out as a TWIG file:
file_put_contents('path/to/file.twig', $pageHtml);
When I look at this file, I now have as the script tag:
<script src="%7B%7B%20asset('path/to/asset.js')%20%7D%7D"></script>
What I need to have is:
<script src="{{ asset('path/to/asset.js') }}"></script>
So I somehow need to stop it doing url encoding. Any way to do this?