[SOLVED] Generate XML file with smarty

The place to talk about things that are related to CMS Made simple, but don't fit anywhere else.
Post Reply
akke
Forum Members
Forum Members
Posts: 13
Joined: Tue Jan 18, 2011 4:00 pm

[SOLVED] Generate XML file with smarty

Post 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>
Last edited by akke on Wed Jun 05, 2013 10:23 am, edited 1 time in total.
psy
Power Poster
Power Poster
Posts: 463
Joined: Sat Jan 22, 2005 11:19 am

Re: Generate XML file with smarty

Post 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.
User avatar
Rolf
Power Poster
Power Poster
Posts: 7825
Joined: Wed Apr 23, 2008 7:53 am
Location: The Netherlands
Contact:

Re: Generate XML file with smarty

Post by Rolf »

- + - + - + - + - + - + -
LATEST TUTORIAL AT CMS CAN BE SIMPLE:
Migrating Company Directory module to LISE
- + - + - + - + - + - + -
Image
akke
Forum Members
Forum Members
Posts: 13
Joined: Tue Jan 18, 2011 4:00 pm

Re: Generate XML file with smarty

Post 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.
Post Reply

Return to “The Lounge”