I'm writing some exports to move content from our custom Symfony CMS into a new site built on Craft CMS.
To break down an article into separate fields, I'm using DOMDocument to cycle through the elements. This all seems to be working - dumping out the content and then exiting out shows the content I'd expect. Then I prepare a response and pass it to the view template and dump it out and I'm getting malformed characters.
I'm assuming this is something to do with character encoding, but I'm not really sure how.
The code in the controller:
$response = new Response();
$response->headers->set('Content-Type', 'xml');
return $this->render('FrontBundle:Export:articles.html.twig', array(
'pages' => $pages
), $response);
As I say, $pages has been prepared with DOMDocument and shows as expected when dumped out from the controller. e.g:
it’s tough, it’s arduous and it’s laborious
When this is passed to the view, I then get this output:
itâs tough, itâs arduous and itâs laborious
That's coming from this:
<?xml version="1.0" encoding="UTF-8"?>
<pages>
{% for page in pages %}
<page>
<title>{{ page.title }}</title>
<intro>{{ page.article.intro|join('') }}</intro>
<article>
{% for block in page.article.body %}
<block>
<heading>{{ block.heading }}</heading>
</block>
<block>
<content>{{ block.content }}</content>
</block>
{% endfor %}
</article>
</page>
{% endfor %}
</pages>
Though I also don't think it's an XML issue as the same thing happens if I don't set the content-type and just strip the view down to {{ dump(pages) }}
So I'm completely flummoxed - any suggestion would be greatly appreciated!