This module does more for txt that is required.
It adds "[]" before each row and "----------------------------------------" after, without a line feed in between, so rows are separated by "[]----------------------------------------"
Unless this is made configurable, better to do nothing (evrything it possible in the row itself).

I replaced in views-data-export-txt-body.tpl.php.bak.php:

foreach ($themed_rows as $count => $row):
  foreach ($row as $field => $content):
?>
[<?php print $header[$field]; ?>]

<?php print strip_tags($content); // strip html so its plain txt. ?>

<?php endforeach; ?>
----------------------------------------

<?php endforeach;

by

foreach ($themed_rows as $count => $row):
  foreach ($row as $field => $content):
?>
<?php print strip_tags($content); // strip html so its plain txt. ?>
<?php endforeach; ?>
<?php endforeach;

Comments

jvieille’s picture

Actually, stripping all html gives no way to control the output, ie carriage return are impossible.

The correct code in views-data-export-txt-body.tpl.php for using txt output is the following:

<?php
/**
 * @file views-view-table.tpl.php
 * Template to display a view as a table.
 *
 * - $title : The title of this group of rows.  May be empty.
 * - $rows: An array of row items. Each row is an array of content
 *   keyed by field ID.
 * - $header: an array of haeaders(labels) for fields.
 * - $themed_rows: a array of rows with themed fields.
 * @ingroup views_templates
 */
/*<?php print strip_tags($content); // strip html so its plain txt. ?>*/
foreach ($themed_rows as $count => $row):
  foreach ($row as $field => $content):
?>

<?php print $content; ?>
<?php endforeach; ?>
<?php endforeach;
steven jones’s picture

Version: 6.x-2.x-dev » 7.x-3.x-dev
Category: bug » feature
Status: Needs review » Active

Maybe we should change text format so that less is output by default, then one could use rewrite field magic to get it to the correct format as desired.

steven jones’s picture

Maybe we should just provide a way to use a plainer output through the UI.

pzzd’s picture

A UI change to support more flexible formatting would be really great!

In the meantime, I was able to easily reformat the text output by making a template file. Here's how:

In Views - Other - Theme: Information - Alternative style, the template file name is listed there in bold. In my case, I'm formatting results for a RePEc submission, so the template is called 'views-data-export-txt-body--repec-templates.tpl.php'.

I created a new file at /sites/all/themes/mycustomtheme/templates/views-data-export-txt-body--repec-templates.tpl.php and tweaked the PHP for the right formatting. That started working immediately at https://mylovelysite.edu/repectemplates.

<?php
/**
 * @file views-data-export-txt-body--repec-templates.tpl.php
 * Template to display a view as a table.
 *
 * - $title : The title of this group of rows.  May be empty.
 * - $rows: An array of row items. Each row is an array of content
 *   keyed by field ID.
 * - $header: an array of haeaders(labels) for fields.
 * - $themed_rows: a array of rows with themed fields.
 * @ingroup views_templates
 */

foreach ($themed_rows as $count => $row):
  foreach ($row as $field => $content):
?>
<?php print $header[$field]; ?>: <?php print strip_tags($content); // strip html so its plain txt. ?>

<?php endforeach; ?>

<?php endforeach;

nwom’s picture

I agree. An option to remove both the "---------------" and "[]" would be amazing.

nwom’s picture

Thanks to your template snippets, I was able to create exactly what I needed. Thanks!

I needed each row to be a new line and both the brackets and the lines removed. Here is the template that I ended up with.

<?php
/**
 * @file views-view-table.tpl.php
 * Template to display a view as a table.
 *
 * - $title : The title of this group of rows.  May be empty.
 * - $rows: An array of row items. Each row is an array of content
 *   keyed by field ID.
 * - $header: an array of haeaders(labels) for fields.
 * - $themed_rows: a array of rows with themed fields.
 * @ingroup views_templates
 */

foreach ($themed_rows as $count => $row):
  foreach ($row as $field => $content):
?>
<?php print $header[$field]; ?>

<?php print strip_tags($content); // strip html so its plain txt. ?>

<?php endforeach; ?>
<?php print "\r\n"; ?>
<?php endforeach;
nwom’s picture

Title: txt export add unrequested separators [] ---------------------------------------- » Please make txt export separator "[]" & linebreaks configurable/optional
steven jones’s picture

Issue summary: View changes
Status: Active » Closed (won't fix)

Sorry for the lack of attention to your issue, please accept my apologies.

Drupal 7 is going to be end-of-life'd by the community in approximately 1 month.

As such, I am closing all non-critical looking, non-PHP compatibility issues for Views Data Export to tidy up the issue queues and reduce the noise. You can read about this on #3492246: Close down Drupal 7 issues.

If you feel like this issue has been closed by mistake, please do comment about re-opening it.
If you feel like the ticket is still relevant for the 8.x-1.x version of the module, then please search for a duplicate issue first, and if there really isn't one (and you've looked properly) then change the version on the ticket and re-open.

Thanks to everyone involved in this issue: for reporting it, and moving it along, it is truly appreciated.
The Drupal community wouldn't be what it is today without your involvement and effort, so I'm sorry that we couldn't get this issue resolved. Hopefully we'll work together in a future issue though, and get that one resolved :)