Page 1 of 1

[SOLVED] Generate XML file with smarty

Posted: Wed May 22, 2013 10:31 am
by akke
I have only this code in a tpl:

Code: Select all

{php}
			ob_end_clean();
			header('Content-Description: File Transfer');
			header('Content-Type: application/force-download');
			header('Content-Disposition: attachment; filename=file.xml');
{/php}
<?xml version="1.0" encoding="UTF-8"?>
<filmer>
{section name=element loop=$list}
  <film>  
    <tittel>{$list[element].tittel}</tittel>
    <image href="{$list[element].plakat_url}"></image>
    <tekst>{$list[element].ingress}</tekst>
    <genre>{$list[element].genre}</genre>
    <sensur>{$list[element].sensur}</sensur>
  </film>
{/section}
</filmer>
{php}
exit();
{/php}
The xml file is saved, but line 1 is always

Code: Select all

<div class="pagecontainer"><div class="pageoverflow"></div>
How to get rid of that?

Examle of complete file.xml content

Code: Select all

<div class="pagecontainer"><div class="pageoverflow"></div>
<?xml version="1.0" encoding="UTF-8"?>
<filmer>
  <film>  
    <tittel>Star Trek Into Darkness</tittel>
    <image href="http://www.xx.xx/image.jpg"></image>
    <tekst>Den banebrytende regissøren J.J. Abrams gir deg sommeren 2013 en eksplosiv actionthriller som bygger videre på Star Trek-universet.</tekst>
    <genre>Action/Eventyr/Sci-Fi</genre>
    <sensur>11</sensur>
  </film>
</filmer>

Re: Generate XML file with smarty

Posted: Sun May 26, 2013 10:24 pm
by psy
Do all your PHP processing, including the loop that generates the xml content, in PHP.

Better still, instead of using {php} tags, create a Smarty plugin then use the plugin tag with a param loop=$list to pass the data to it, in your template.

Re: Generate XML file with smarty

Posted: Sun May 26, 2013 10:57 pm
by Rolf

Re: Generate XML file with smarty

Posted: Wed Jun 05, 2013 10:22 am
by akke
psy wrote:Do all your PHP processing, including the loop that generates the xml content, in PHP.

Better still, instead of using {php} tags, create a Smarty plugin then use the plugin tag with a param loop=$list to pass the data to it, in your template.
Thanks, will create a plugin.