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:

    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");

Inside the snippet is

{if segment_2=='html-template'}<table>
      <th>Line type</th>
      <th>Campaign Daily Budget</th>
      <th>Campaign Type</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>Criterion type</th>
      <th>Headline 1</th>
      <th>Headline 2</th>
      <th>Path 1</th>
      <th>Path 2</th>
      <th>Link text</th>
      <th>Feed name</th>
      <th>Snippet Values</th>
  {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}
  {if segment_2=='filter-urls'}</tbody>

And inside the embedded template:

    {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}

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?

1 Answer 1


You can use a wonderful EE utility called Streeng to do this (and lots of other things).

Streeng performs a broad variety of manipulations on the tag outputs, including stripping out some or all of the <html> tags within it, and performing substitutions. You could use these features to achieve what you are describing (and remove the conditional statements used in your code at same time).

With Streeng installed, to get a version of the tag output with <html> tags removed and the line feeds replaced by single spaces you would need to enclose the tag as follows:

{exp:streeng allowed="none" find="NEWLINE" replace=" "} {sn_filter_urls} {/exp:streeng}



In response to your comment about it not working, I did this test:

Create template partial {sn_test_text} containing:

Here is some stuff
Here is a new line 
Here is the last line.

Then created a template with this code in:

  replace=" "}

And then when I run the template I get this output

Here is some stuff Here is a new line Here is the last line.
  • Doesn't seem to work when wrapped around a snippet.
    – Tyssen
    Oct 11, 2017 at 0:08
  • hmm. interesting, works fine here - what output do you get? Have appended test results to answer above. Oct 11, 2017 at 11:52
  • The snippet contains some embeds which is where I guess it's falling down.
    – Tyssen
    Oct 11, 2017 at 22:26
  • You could try adding parse="inward" to the streeng tag - or post what you actually have here and I could have a look Oct 12, 2017 at 8:34
  • I've added more code to the original question but I'm thinking I'm just going to have to go with two separate templates rather than trying to work with a single snippet for both.
    – Tyssen
    Oct 16, 2017 at 4:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.