diff --git a/FAQ b/FAQ index b54e9d82..494b92df 100644 --- a/FAQ +++ b/FAQ @@ -38,24 +38,30 @@ A: Smarty and these cache solutions have nothing in common. What APC does is not. Q: Is Smarty faster than ? -A: This would mostly depend on the other template engine, but as a - general rule of thumb: Without a PHP caching solution like APC or - Zend Cache, Smarty is most likely as fast, or possibly slower. With - APC, Smarty is mostly like as fast or much faster. The reason is - this: Smarty generates PHP scripts from your templates. The more - templates your application has, the more PHP scripts Smarty - generates. This in turn requires more time for the PHP parser to - compile the PHP scripts. With APC, this compilation step is cached. - So as the complexity of the templates increase, the performance - savings go up accordingly. Also, most other template solutions parse - the template files on each invocation. The more complex the - templates are, the longer they take to parse them. +A: This would mostly depend on the other template engine, but as a general rule + of thumb: Without a PHP caching solution like APC or Zend Cache, Smarty is + most likely as fast, or possibly slower. With APC, Smarty is mostly like as + fast or much faster. The reason is this: Smarty generates PHP scripts from + your templates. The more templates your application has, the more PHP + scripts Smarty generates. This in turn requires more time for the PHP parser + to compile the PHP scripts. With APC, this compilation step is cached. So as + the complexity of the templates increase, the performance savings go up + accordingly. Also, most other template solutions parse the template files on + each invocation. The more complex the templates are, the longer they take to + parse. Smarty has no need to parse template files, it only executes PHP + scripts. We are working on a release of Smarty that will be noticably + quicker even without the aid of a PHP script caching solution by minimizing + the amount of PHP code that is compiled on each request. - The above comparison assumes that you are not using Smarty's - built-in ability to cache templates. If you are, that makes this - comparison pretty useless since Smarty will basically be displaying - static content instead of generating templates, which of course will - be magnitudes faster. + The above comparison assumes that you are not using Smarty's built-in + ability to cache templates. If you are, that makes this comparison pretty + useless since Smarty will basically be displaying static content instead of + generating templates, which of course will be magnitudes faster. + +Q: Can I use Macromedia's Dreamweaver to edit my templates? +A: Certainly. You might want to change your tag delimiters from {} to something + that resembles valid HTML, like or <{ }> or something similar. + This way the editor won't view the template tags as errors. Q: Do you have a mailing list? A: Yes. Subscribe by sending an e-mail to subscribe-smarty@lists.ispi.net. This @@ -105,3 +111,10 @@ A: This may be the result of your compile or cache settings. If you are specifically testing it. You can also remove everything from your compile_dir and cache_dir and reload the page to be sure everything gets regenerated. + +Q: I'm running Windows 2000 and I get blank content. My compiled PHP files are + also zero length. +A: There seems to be a problem with some W2k machines and exclusive file + locking. Comment out the flock() call in _write_file to get around this, + although be aware this could possibly cause a problem with simultaneous + writes to a file, especially with caching turned on. diff --git a/Smarty.class.php b/Smarty.class.php index 4215604e..3f77b4aa 100644 --- a/Smarty.class.php +++ b/Smarty.class.php @@ -82,8 +82,7 @@ class Smarty var $left_delimiter = '{'; // template tag delimiters. var $right_delimiter = '}'; - - + var $custom_funcs = array( 'html_options' => 'smarty_func_html_options', 'html_select_date' => 'smarty_func_html_select_date', 'math' => 'smarty_func_math' @@ -101,7 +100,7 @@ class Smarty 'strip_tags' => 'smarty_mod_strip_tags', 'default' => 'smarty_mod_default' ); - + // internal vars var $_error_msg = false; // error messages. true/false var $_tpl_vars = array(); diff --git a/docs.sgml b/docs.sgml index 9acf13f0..a037adb2 100644 --- a/docs.sgml +++ b/docs.sgml @@ -2026,6 +2026,95 @@ OUTPUT: <option value="2001">2001</option> </select> + + + + + math + + + + + + + + + + Attribute Name + Type + Required + Default + Description + + + + + equation + string + Yes + n/a + the equation to execute + + + var + numeric + Yes + n/a + equation variable value + + + ...[var] + numeric + Yes + n/a + equation varible value + + + + + + math allows the template designer to do math equations in the + template. Any numeric template variables may be used in the + equations, and the result is printed in place of the tag. The + variables used in the equation are passed as parameters, which can + be template variables or static values. +, -, /, *, abs, ceil, cos, + exp, floor, log, log10, max, min, pi, pow, rand, round, sin, sqrt, + srans and tan are all valid operators. Check the PHP documenation + for further information on these math functions. + + +math + + +{* $height=4, $width=5 *} + +{math equation="x + y" x=$height y=$width} + +OUTPUT: + +9 + + +{* $row_height = 10, $row_width = 20, #col_div# = 2, assigned in template *} + +{math equation="height * padding / division" + height=$row_height + width=$row_width + division=#col_div#} + +OUTPUT: + +100 + + +{* you can use parenthesis *} + +{math equation="(( x + y ) / z )" x=2 y=10 z=2} + +OUTPUT: + +6 + diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index 4215604e..3f77b4aa 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -82,8 +82,7 @@ class Smarty var $left_delimiter = '{'; // template tag delimiters. var $right_delimiter = '}'; - - + var $custom_funcs = array( 'html_options' => 'smarty_func_html_options', 'html_select_date' => 'smarty_func_html_select_date', 'math' => 'smarty_func_math' @@ -101,7 +100,7 @@ class Smarty 'strip_tags' => 'smarty_mod_strip_tags', 'default' => 'smarty_mod_default' ); - + // internal vars var $_error_msg = false; // error messages. true/false var $_tpl_vars = array();