I'm working on two templates which use the same snippet for outputting data. One is a HTML template which displays a table, the other forces the download of a CSV.
With some conditionals I've set up my snippet to replace all table tags with either nothing, spaces or commas for the CSV delimiters, but the CSV output still has all the line breaks which I'd ideally like to keep in place so that I can still actually read the template when I need to edit it.
The template that downloads the CSV looks like this:
<?php
header('Content-type: text/csv');
header("Content-Disposition: attachment; filename=file-{current_time format='%d-%m-%Y'}.csv");
header("Pragma: no-cache");
header("Expires: 0");
?>
{sn_filter_urls}
Inside the snippet is
{if segment_2=='html-template'}<table>
<thead>
<tr>
<th>Line type</th>
<th>Campaign</th>
<th>Labels</th>
<th>Campaign Daily Budget</th>
<th>Campaign Type</th>
<th>Networks</th>
<th>Languages</th>
<th>Bid Strategy Type</th>
<th>Enhanced CPC</th>
<th>Ad Rotation</th>
<th>Delivery Method</th>
<th>Ad Group</th>
<th>Max CPC</th>
<th>Final URL</th>
<th>ID</th>
<th>Location</th>
<th>Criterion type</th>
<th>Keyword</th>
<th>Description</th>
<th>Headline 1</th>
<th>Headline 2</th>
<th>Path 1</th>
<th>Path 2</th>
<th>Comment</th>
<th>Link text</th>
<th>Feed name</th>
<th>Header</th>
<th>Snippet Values</th>
</tr>
</thead>
<tbody>
{/if}
{if segment_2=='csv-template'}Campaign,Labels,Campaign Daily Budget,Campaign Type,Networks,Languages,Bid Strategy Type,Enhanced CPC,Ad Rotation,Delivery Method,Ad Group,Max CPC,Final URL,ID,Location,Criterion type,Keyword,Description,Headline 1,Headline 2,Path 1,Path 2,Comment,Link text,Feed name,Header,Snippet Values{/if}
{exp:channel:entries}
{embed='_embeds/.filter_url_activity_title'}
{/exp:channel:entries}
{if segment_2=='filter-urls'}</tbody>
</table>{/if}
And inside the embedded template:
{exp:channel:entries}
{exp:super_search:results}
{if segment_2=='html-template'}<tr>{/if}
{if segment_2=='html-template'}<td>{/if}DATA{if segment_2=='html-template'}</td>{if:else},{/if}
{exp:loopee forint="1" to="17" by="1"}{if segment_2=='filter-urls'}<td></td>{if:else},{/if}{/exp:loopee}
… other table markup …
{if segment_2=='html-template'}</tr>{/if}
{sn_sitelinks}
{/exp:super_search:results}
{/exp:channel:entries}
There's another snippet in there which also has similar table markup but the problem with the line breaks exists in the short example above. Wherever I'm using loopee to output markup or ,
the ,
all come out on one line which is what I want, but where I've put line breaks in my template so a new td
starts on a new line, that's showing up in the CSV output.
Is there a way I can have the contents of sn_filter_urls
run through a process to remove the line breaks before it's then downloaded?