Differences

This shows you the differences between two versions of the page.

plaintext [2009/10/13 08:54]
Kornel created
plaintext [2015/11/26 10:37] (current)
2001:8b0:1151:da70:ec87:8fcf:9c8e:eb99 old revision restored
Line 5: Line 5:
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 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.+For plaintext, you can use standard PHP or Smarty-like as a templating language. Their ignorance of 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 ===== ===== Using PHPTAL's variables outside PHPTAL templates =====
Line 11: Line 11:
If you want to reuse variables from PHPTAL object in raw PHP templates, then use: If you want to reuse variables from PHPTAL object in raw PHP templates, then use:
-  <?php  +<code php><?php  
-    $ctx = $phptal->getContext();  +  $ctx = $phptal->getContext();  
-  ?>+?></code>
-  <?= $ctx->variable_name ?>+<code php><?= $ctx->variable_name ?></code>
You can also access TALES paths outside templates: You can also access TALES paths outside templates:
-  <?= phptal_path($ctx, "tales/path/to/variable"); ?>+<code php><?= phptal_path($ctx, "tales/path/to/variable"); ?></code>
===== Other approaches ===== ===== Other approaches =====
Line 25: Line 25:
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: 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(); +<code php> 
-   $markup = preg_replace('/s+/',' ',$markup); // normalize whitespace +$markup = $phptal->execute(); 
-   $markup = preg_replace('<(p|ul|ol)',"\n\n<\1", $markup); // add newlines +$markup = preg_replace('/s+/',' ',$markup); // normalize whitespace 
-   $markup = preg_replace('<(br|li)',"\n<\1", $markup); // add newlines +$markup = preg_replace('<(p|ul|ol)',"\n\n<\1", $markup); // add newlines 
-   $text = html_entity_decode(strip_tags($markup),ENT_QUOTES,'UTF-8')); // remove tags and entities+$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 
 +</code>