How do I export search results as a csv? I have set up a custom search of entries on a page in my Craft site which includes filters to filter the results.  I would like to be able to export these results (filtered or otherwise) as a CSV through a link on the page:
http://www.joycefdn.org/grants

Is there a way to do this?
You can just make link to a twig template to output a csv quite simply...just like any other template really, except it won't extend you layout etc. and will simply contain something like:

{%for result in results %}
    {{var1}},{{var2}},{{var3}} etc...
{% endfor %}


Depending on what sort of csv you're after and what you're going to do with the data, you may want to consider escaping the data as you output it:

http://twig.sensiolabs.org/doc/filters/escape.html

In terms of setting it up as a  link, your csv template could just accept the same search parameters passed through and essentially repeat the search and output the csv results as above.

I.e. in your original results page you could build the link to the CSV as 

&lt;a href="/utility/csvmaker?q={{q}}"&gt;Get Results As CSV&lt;/a&gt;


And then in the csvmaker

{% set results = craft.entries.search(q).order('score') %}
...etc as above


But a lot depends on how you've built your search in the first place really.

If you want it to trigger an actual file download, then I've found that's pretty easy to do that on the front end with some JS, e.g. I use this:

https://stackoverflow.com/questions/19721439/download-json-object-as-a-file-from-browser/20343999