mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-06 19:34:27 +02:00
update FAQ, add math functions & update documetation
This commit is contained in:
47
FAQ
47
FAQ
@@ -38,24 +38,30 @@ A: Smarty and these cache solutions have nothing in common. What APC does is
|
|||||||
not.
|
not.
|
||||||
|
|
||||||
Q: Is Smarty faster than <insert other PHP template engine>?
|
Q: Is Smarty faster than <insert other PHP template engine>?
|
||||||
A: This would mostly depend on the other template engine, but as a
|
A: This would mostly depend on the other template engine, but as a general rule
|
||||||
general rule of thumb: Without a PHP caching solution like APC or
|
of thumb: Without a PHP caching solution like APC or Zend Cache, Smarty is
|
||||||
Zend Cache, Smarty is most likely as fast, or possibly slower. With
|
most likely as fast, or possibly slower. With APC, Smarty is mostly like as
|
||||||
APC, Smarty is mostly like as fast or much faster. The reason is
|
fast or much faster. The reason is this: Smarty generates PHP scripts from
|
||||||
this: Smarty generates PHP scripts from your templates. The more
|
your templates. The more templates your application has, the more PHP
|
||||||
templates your application has, the more PHP scripts Smarty
|
scripts Smarty generates. This in turn requires more time for the PHP parser
|
||||||
generates. This in turn requires more time for the PHP parser to
|
to compile the PHP scripts. With APC, this compilation step is cached. So as
|
||||||
compile the PHP scripts. With APC, this compilation step is cached.
|
the complexity of the templates increase, the performance savings go up
|
||||||
So as the complexity of the templates increase, the performance
|
accordingly. Also, most other template solutions parse the template files on
|
||||||
savings go up accordingly. Also, most other template solutions parse
|
each invocation. The more complex the templates are, the longer they take to
|
||||||
the template files on each invocation. The more complex the
|
parse. Smarty has no need to parse template files, it only executes PHP
|
||||||
templates are, the longer they take to parse them.
|
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
|
The above comparison assumes that you are not using Smarty's built-in
|
||||||
built-in ability to cache templates. If you are, that makes this
|
ability to cache templates. If you are, that makes this comparison pretty
|
||||||
comparison pretty useless since Smarty will basically be displaying
|
useless since Smarty will basically be displaying static content instead of
|
||||||
static content instead of generating templates, which of course will
|
generating templates, which of course will be magnitudes faster.
|
||||||
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?
|
Q: Do you have a mailing list?
|
||||||
A: Yes. Subscribe by sending an e-mail to subscribe-smarty@lists.ispi.net. This
|
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
|
specifically testing it. You can also remove everything from your
|
||||||
compile_dir and cache_dir and reload the page to be sure everything gets
|
compile_dir and cache_dir and reload the page to be sure everything gets
|
||||||
regenerated.
|
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.
|
||||||
|
@@ -82,8 +82,7 @@ class Smarty
|
|||||||
|
|
||||||
var $left_delimiter = '{'; // template tag delimiters.
|
var $left_delimiter = '{'; // template tag delimiters.
|
||||||
var $right_delimiter = '}';
|
var $right_delimiter = '}';
|
||||||
|
|
||||||
|
|
||||||
var $custom_funcs = array( 'html_options' => 'smarty_func_html_options',
|
var $custom_funcs = array( 'html_options' => 'smarty_func_html_options',
|
||||||
'html_select_date' => 'smarty_func_html_select_date',
|
'html_select_date' => 'smarty_func_html_select_date',
|
||||||
'math' => 'smarty_func_math'
|
'math' => 'smarty_func_math'
|
||||||
@@ -101,7 +100,7 @@ class Smarty
|
|||||||
'strip_tags' => 'smarty_mod_strip_tags',
|
'strip_tags' => 'smarty_mod_strip_tags',
|
||||||
'default' => 'smarty_mod_default'
|
'default' => 'smarty_mod_default'
|
||||||
);
|
);
|
||||||
|
|
||||||
// internal vars
|
// internal vars
|
||||||
var $_error_msg = false; // error messages. true/false
|
var $_error_msg = false; // error messages. true/false
|
||||||
var $_tpl_vars = array();
|
var $_tpl_vars = array();
|
||||||
|
89
docs.sgml
89
docs.sgml
@@ -2026,6 +2026,95 @@ OUTPUT:
|
|||||||
<option value="2001">2001</option>
|
<option value="2001">2001</option>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
</programlisting>
|
||||||
|
</example>
|
||||||
|
</sect2>
|
||||||
|
<sect2>
|
||||||
|
<title>math</title>
|
||||||
|
<informaltable frame=all>
|
||||||
|
<tgroup cols=3>
|
||||||
|
<colspec colname=param>
|
||||||
|
<colspec colname=type>
|
||||||
|
<colspec colname=required>
|
||||||
|
<colspec colname=default>
|
||||||
|
<colspec colname=desc>
|
||||||
|
<thead>
|
||||||
|
<row>
|
||||||
|
<entry>Attribute Name</entry>
|
||||||
|
<entry>Type</entry>
|
||||||
|
<entry>Required</entry>
|
||||||
|
<entry>Default</entry>
|
||||||
|
<entry>Description</entry>
|
||||||
|
</row>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<row>
|
||||||
|
<entry>equation</entry>
|
||||||
|
<entry>string</entry>
|
||||||
|
<entry>Yes</entry>
|
||||||
|
<entry><emphasis>n/a</emphasis></entry>
|
||||||
|
<entry>the equation to execute</entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry>var</entry>
|
||||||
|
<entry>numeric</entry>
|
||||||
|
<entry>Yes</entry>
|
||||||
|
<entry><emphasis>n/a</emphasis></entry>
|
||||||
|
<entry>equation variable value</entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry>...[var]</entry>
|
||||||
|
<entry>numeric</entry>
|
||||||
|
<entry>Yes</entry>
|
||||||
|
<entry><emphasis>n/a</emphasis></entry>
|
||||||
|
<entry>equation varible value</entry>
|
||||||
|
</row>
|
||||||
|
</tbody>
|
||||||
|
</tgroup>
|
||||||
|
</informaltable>
|
||||||
|
<para>
|
||||||
|
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.
|
||||||
|
</para>
|
||||||
|
<example>
|
||||||
|
<title>math</title>
|
||||||
|
<programlisting>
|
||||||
|
|
||||||
|
{* $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
|
||||||
|
|
||||||
</programlisting>
|
</programlisting>
|
||||||
</example>
|
</example>
|
||||||
</sect2>
|
</sect2>
|
||||||
|
@@ -82,8 +82,7 @@ class Smarty
|
|||||||
|
|
||||||
var $left_delimiter = '{'; // template tag delimiters.
|
var $left_delimiter = '{'; // template tag delimiters.
|
||||||
var $right_delimiter = '}';
|
var $right_delimiter = '}';
|
||||||
|
|
||||||
|
|
||||||
var $custom_funcs = array( 'html_options' => 'smarty_func_html_options',
|
var $custom_funcs = array( 'html_options' => 'smarty_func_html_options',
|
||||||
'html_select_date' => 'smarty_func_html_select_date',
|
'html_select_date' => 'smarty_func_html_select_date',
|
||||||
'math' => 'smarty_func_math'
|
'math' => 'smarty_func_math'
|
||||||
@@ -101,7 +100,7 @@ class Smarty
|
|||||||
'strip_tags' => 'smarty_mod_strip_tags',
|
'strip_tags' => 'smarty_mod_strip_tags',
|
||||||
'default' => 'smarty_mod_default'
|
'default' => 'smarty_mod_default'
|
||||||
);
|
);
|
||||||
|
|
||||||
// internal vars
|
// internal vars
|
||||||
var $_error_msg = false; // error messages. true/false
|
var $_error_msg = false; // error messages. true/false
|
||||||
var $_tpl_vars = array();
|
var $_tpl_vars = array();
|
||||||
|
Reference in New Issue
Block a user