Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Export a CSV without markup and trace log
Stupid question, and I’m sure I’ve solved this before but can’t find the answer. If I want to create a page template that puts a form at the top to allow someone to select articles to export (section, date range, modified since, etc), and then a shiny Go button that will submit the form and spit out a CSV file of the chosen records, how do I get the CSV file to be served with the mime header but NOT have any of the trace info when the site is running in debugging/testing modes (which I do from time to time). That knackers up the CSV file.
<txp:header name="Content-Disposition" value='attachment;filename=products-<txp:date format="yyyy-MM-dd" />.csv' />
<txp:header name="Content-Type" value="text/csv" />
<article::custom with attributes read from form submission>
<txp:article_field 1 />,
<txp:article_field 2 />,
...
</article::custom>
I’ve tried adding <txp:txp_die status="200"/>
to the end but that just serves an OK page.
I’ve tried adding <txp:php>exit;</txp:php>
to the end but that just kills all output.
I’ve tried adding <txp:php>ob_flush();</txp:php>
to the end but it makes no difference.
Is there a better way to output CSVs e.g. using ?f=
? Or should I be using PHP instead of Txp tags (e.g. fputcsv()
) and use parse()
inside PHP blocks to output the dynamic tag content? I’d rather do it in tags if I can because it makes it more readable for others to tweak the output.
I’m obviously missing something simple. Any ideas please?
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline