This shows you the differences between two versions of the page.
plaintext [2015/11/26 01:55] 188.10.249.65 AWJmyP4xOu6 |
plaintext [2015/11/26 10:37] (current) 2001:8b0:1151:da70:ec87:8fcf:9c8e:eb99 old revision restored |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | I actually found this more ennittainerg than James Joyce. | + | ====== 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-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 ===== | ||
+ | |||
+ | If you want to reuse variables from PHPTAL object in raw PHP templates, then use: | ||
+ | |||
+ | <code php><?php | ||
+ | $ctx = $phptal->getContext(); | ||
+ | ?></code> | ||
+ | |||
+ | <code php><?= $ctx->variable_name ?></code> | ||
+ | |||
+ | You can also access TALES paths outside templates: | ||
+ | |||
+ | <code php><?= phptal_path($ctx, "tales/path/to/variable"); ?></code> | ||
+ | |||
+ | ===== 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: | ||
+ | |||
+ | <code php> | ||
+ | $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 | ||
+ | </code> |