Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.3.0

Request #12221 template comments, a new option 'charset' and 2 new buildin functions
Submitted: 2007-10-11 09:28 UTC
From: cwiedmann Assigned: avb
Status: Closed Package: HTML_Template_Sigma (version 1.1.6)
PHP Version: Irrelevant OS: Irrelevant
Roadmaps: (Not assigned)    
Subscription  


 [2007-10-11 09:28 UTC] cwiedmann (Carsten Wiedmann)
Description: ------------ Hello, I have 5 additions for this class: 1) having comments in the template files, which are not part of the browser output 2) having a option 'charset', which is currently used for the buildin functions 'h' and 'e' 3) adding a buildin function 'r' (rawurlencode), which is IMHO more often used then urlencode. 4) adding a buildin function 'e' (htmlentities). 5) Options can now be an array and an optional parameter for the class constructor. Regards, Carsten BTW: A htmlentities() without the charset parameter, would result in this script in: | <h1>this is a test with a german "ä"</h1> Test script: --------------- <?php require_once 'HTML/Template/Sigma.php'; $tpl_file = tempnam('.', 'tpl'); $tpl_content = <<<EOD <!-- COMMENT charset=utf-8 --> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>test template</title> </head> <body> <h1>{header:e}</h1> <a href="http://example.com/{uri:r}/">test uri</a> </body> </html> EOD; file_put_contents($tpl_file, utf8_encode($tpl_content)); $tplOptions = array( 'charset' => 'UTF-8' ); $tpl = new HTML_Template_Sigma(dirname($tpl_file), null, $tplOptions); $tpl->loadTemplateFile(basename($tpl_file)); $tpl->setVariable(array( 'header' => utf8_encode('this is a test with a german "ä"'), 'uri' => utf8_encode('foo bar') )); $tpl->show(); ?> Expected result: ---------------- <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>test template</title> </head> <body> <h1>this is a test with a german "ä"</h1> <a href="http://example.com/foo%20bar/">test uri</a> </body> </html> Actual result: -------------- <!-- COMMENT charset=utf-8 --> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>test template</title> </head> <body> <h1>this is a test with a german "ä"</h1> <a href="http://example.com/foo+bar/">test uri</a> </body> </html>

Comments

 [2008-07-22 19:27 UTC] avb (Alexey Borzov)
Partially implemented in release 1.2.0 Didn't add possibility to pass options to the constructor, since setOption() can return errors but we don't have a means to return errors from the constructor in PHP4. Also didn't add the possibility to set options as the array, I don't think that task of setting options is so common. Also the comment syntax is a bit different from that proposed in the patch.