Table of Contents

Plaintext is not XML

PHPTAL intentionally doesn't support plaintext output.

For plaintext you don't need automatic escaping, strict syntax/structure checks (which are strengths of PHPTAL), but you need precise control of whitespace (which is hard to do in XML).

For plaintext, you can use standard PHP or Smarty as a templating language. Their ignorance about structure and lack of escaping by default, which are troublesome for XML, are exactly what you need for plain text.

Using PHPTAL's variables outside PHPTAL templates

If you want to reuse variables from PHPTAL object in raw PHP templates, then use:

<?php 
  $ctx = $phptal->getContext(); 
?>
<?= $ctx->variable_name ?>

You can also access TALES paths outside templates:

<?= phptal_path($ctx, "tales/path/to/variable"); ?>

Other approaches

If you need both [X]HTML and plaintext version of a page, then you can try to convert XHTML to plain text. Here's a quick'n'dirty way:

$markup = $phptal->execute();
$markup = preg_replace('/s+/',' ',$markup); // normalize whitespace
$markup = preg_replace('<(p|ul|ol)',"\n\n<\1", $markup); // add newlines
$markup = preg_replace('<(br|li)',"\n<\1", $markup); // add newlines
$text = html_entity_decode(strip_tags($markup),ENT_QUOTES,'UTF-8')); // remove tags and entities