mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-07 20:04:27 +02:00
update changelog
This commit is contained in:
30
FAQ
30
FAQ
@@ -38,25 +38,23 @@ 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 general rule
|
A: It could be. One of the strengths of Smarty is that it does not need to
|
||||||
of thumb: Without a PHP caching solution like APC or Zend Cache, Smarty is
|
parse the template files on every hit to the server. Version 1.3.1 has
|
||||||
most likely as fast, or possibly slower. With APC, Smarty is mostly like as
|
many noticable performance tune-ups, so your best bet is to try some
|
||||||
fast or much faster. The reason is this: Smarty generates PHP scripts from
|
benchmarks and compare for yourself.
|
||||||
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
|
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
|
ability to cache templates. If you are, that makes this comparison pretty
|
||||||
useless since Smarty will basically be displaying static content instead of
|
unfair since Smarty will basically be displaying static content instead of
|
||||||
generating templates, which of course will be magnitudes faster.
|
generating templates, which will speed things up, especially for compilcated
|
||||||
|
templates.
|
||||||
|
|
||||||
|
Q: How can I be sure to get the best performance from Smarty?
|
||||||
|
A Be sure you set $compile_check=false once your templates are initially
|
||||||
|
compiled. This will skip the unneeded step of traversing all of your template files on each hit. If you have complex pages that don't change too often,
|
||||||
|
turn on the caching engine and adjust your application so it doesn't do
|
||||||
|
unnecessary work (like db calls) if a cached page is available. See the
|
||||||
|
documentation for examples.
|
||||||
|
|
||||||
Q: Can I use Macromedia's Dreamweaver to edit my templates?
|
Q: Can I use Macromedia's Dreamweaver to edit my templates?
|
||||||
A: Certainly. You might want to change your tag delimiters from {} to something
|
A: Certainly. You might want to change your tag delimiters from {} to something
|
||||||
|
2
NEWS
2
NEWS
@@ -1,6 +1,8 @@
|
|||||||
|
- document first, last, index_prev, index_next (Monte)
|
||||||
- added 'first' and 'last' section properties. (Andrei)
|
- added 'first' and 'last' section properties. (Andrei)
|
||||||
- split out compiling code to separate class for faster template execution
|
- split out compiling code to separate class for faster template execution
|
||||||
time (Monte)
|
time (Monte)
|
||||||
|
- fixed a couple of minor PHP warnings (Monte)
|
||||||
- added and documented unregister_modifier() and unregister_function() API
|
- added and documented unregister_modifier() and unregister_function() API
|
||||||
calls. (Monte)
|
calls. (Monte)
|
||||||
- added and documented 'fetch' and 'math' functions. (Monte)
|
- added and documented 'fetch' and 'math' functions. (Monte)
|
||||||
|
243
docs.sgml
243
docs.sgml
@@ -580,6 +580,59 @@ function print_current_date ($params) {
|
|||||||
// now you can use this in Smarty to print the current date: {date_now}
|
// now you can use this in Smarty to print the current date: {date_now}
|
||||||
// or, {date_now format="%Y/%m/%d"} to format it.
|
// or, {date_now format="%Y/%m/%d"} to format it.
|
||||||
|
|
||||||
|
</programlisting>
|
||||||
|
</example>
|
||||||
|
</sect2>
|
||||||
|
<sect2 id="api.clear.cache">
|
||||||
|
<title>clear_cache</title>
|
||||||
|
<funcsynopsis>
|
||||||
|
<funcprototype>
|
||||||
|
<funcdef>void <function>clear_cache</function></funcdef>
|
||||||
|
<paramdef>string <parameter>template</parameter></paramdef>
|
||||||
|
<paramdef>string <parameter>cache id</parameter></paramdef>
|
||||||
|
</funcprototype>
|
||||||
|
</funcsynopsis>
|
||||||
|
<para>
|
||||||
|
This clears the cache for the specified template. If you have
|
||||||
|
multiple caches for this template, you can clear a specific
|
||||||
|
cache by supplying the cache id as the second parameter. See the
|
||||||
|
<link linkend="section.caching">caching section</link> for more
|
||||||
|
information. This was added to Smarty 1.3.0.
|
||||||
|
</para>
|
||||||
|
<example>
|
||||||
|
<title>clear_cache</title>
|
||||||
|
<programlisting>
|
||||||
|
|
||||||
|
// clear the cache for a template
|
||||||
|
$smarty->clear_cache("index.tpl");
|
||||||
|
|
||||||
|
// clear the cache for a particular cache id in an multiple-cache template
|
||||||
|
$smarty->clear_cache("index.tpl","CACHEID");
|
||||||
|
|
||||||
|
|
||||||
|
</programlisting>
|
||||||
|
</example>
|
||||||
|
</sect2>
|
||||||
|
<sect2 id="api.clear.all.cache">
|
||||||
|
<title>clear_all_cache</title>
|
||||||
|
<funcsynopsis>
|
||||||
|
<funcprototype>
|
||||||
|
<funcdef>void <function>clear_all_cache</function></funcdef>
|
||||||
|
<paramdef><parameter></parameter></paramdef>
|
||||||
|
</funcprototype>
|
||||||
|
</funcsynopsis>
|
||||||
|
<para>
|
||||||
|
This clears the entire template cache. This was added to Smarty
|
||||||
|
1.3.0.
|
||||||
|
</para>
|
||||||
|
<example>
|
||||||
|
<title>clear_all_cache</title>
|
||||||
|
<programlisting>
|
||||||
|
|
||||||
|
// clear the entire cache
|
||||||
|
$smarty->clear_all_cache();
|
||||||
|
|
||||||
|
|
||||||
</programlisting>
|
</programlisting>
|
||||||
</example>
|
</example>
|
||||||
</sect2>
|
</sect2>
|
||||||
@@ -653,59 +706,6 @@ $smarty->register_modifier("sslash","stripslashes");
|
|||||||
|
|
||||||
$smarty->unregister_modifier("strip_tags");
|
$smarty->unregister_modifier("strip_tags");
|
||||||
|
|
||||||
</programlisting>
|
|
||||||
</example>
|
|
||||||
</sect2>
|
|
||||||
<sect2 id="api.clear.cache">
|
|
||||||
<title>clear_cache</title>
|
|
||||||
<funcsynopsis>
|
|
||||||
<funcprototype>
|
|
||||||
<funcdef>void <function>clear_cache</function></funcdef>
|
|
||||||
<paramdef>string <parameter>template</parameter></paramdef>
|
|
||||||
<paramdef>string <parameter>cache id</parameter></paramdef>
|
|
||||||
</funcprototype>
|
|
||||||
</funcsynopsis>
|
|
||||||
<para>
|
|
||||||
This clears the cache for the specified template. If you have
|
|
||||||
multiple caches for this template, you can clear a specific
|
|
||||||
cache by supplying the cache id as the second parameter. See the
|
|
||||||
<link linkend="section.caching">caching section</link> for more
|
|
||||||
information. This was added to Smarty 1.3.0.
|
|
||||||
</para>
|
|
||||||
<example>
|
|
||||||
<title>clear_cache</title>
|
|
||||||
<programlisting>
|
|
||||||
|
|
||||||
// clear the cache for a template
|
|
||||||
$smarty->clear_cache("index.tpl");
|
|
||||||
|
|
||||||
// clear the cache for a particular cache id in an multiple-cache template
|
|
||||||
$smarty->clear_cache("index.tpl","CACHEID");
|
|
||||||
|
|
||||||
|
|
||||||
</programlisting>
|
|
||||||
</example>
|
|
||||||
</sect2>
|
|
||||||
<sect2 id="api.clear.all.cache">
|
|
||||||
<title>clear_all_cache</title>
|
|
||||||
<funcsynopsis>
|
|
||||||
<funcprototype>
|
|
||||||
<funcdef>void <function>clear_all_cache</function></funcdef>
|
|
||||||
<paramdef><parameter></parameter></paramdef>
|
|
||||||
</funcprototype>
|
|
||||||
</funcsynopsis>
|
|
||||||
<para>
|
|
||||||
This clears the entire template cache. This was added to Smarty
|
|
||||||
1.3.0.
|
|
||||||
</para>
|
|
||||||
<example>
|
|
||||||
<title>clear_all_cache</title>
|
|
||||||
<programlisting>
|
|
||||||
|
|
||||||
// clear the entire cache
|
|
||||||
$smarty->clear_all_cache();
|
|
||||||
|
|
||||||
|
|
||||||
</programlisting>
|
</programlisting>
|
||||||
</example>
|
</example>
|
||||||
</sect2>
|
</sect2>
|
||||||
@@ -1646,6 +1646,134 @@ OUTPUT:
|
|||||||
1 id: 1001<br>
|
1 id: 1001<br>
|
||||||
2 id: 1002<br>
|
2 id: 1002<br>
|
||||||
|
|
||||||
|
</programlisting>
|
||||||
|
</example>
|
||||||
|
</sect3>
|
||||||
|
<sect3>
|
||||||
|
<title>index_prev</title>
|
||||||
|
<para>
|
||||||
|
index_prev is used to display the previous loop iteration.
|
||||||
|
on the first loop, this is set to -1.
|
||||||
|
</para>
|
||||||
|
<example>
|
||||||
|
<title>section property index_prev</title>
|
||||||
|
<programlisting>
|
||||||
|
{section name=customer loop=$custid}
|
||||||
|
{%customer.index%} id: {$customer/custid}<br>
|
||||||
|
{* FYI, $customer.index/custid and $customer/custid are identical in meaning *}
|
||||||
|
{if $customer.index_prev/custid ne $customer.index/custid}
|
||||||
|
The customer id changed<br>
|
||||||
|
{/if}
|
||||||
|
{/section}
|
||||||
|
|
||||||
|
|
||||||
|
OUTPUT:
|
||||||
|
|
||||||
|
0 id: 1000<br>
|
||||||
|
The customer id changed<br>
|
||||||
|
1 id: 1001<br>
|
||||||
|
The customer id changed<br>
|
||||||
|
2 id: 1002<br>
|
||||||
|
The customer id changed<br>
|
||||||
|
|
||||||
|
</programlisting>
|
||||||
|
</example>
|
||||||
|
</sect3>
|
||||||
|
<sect3>
|
||||||
|
<title>index_next</title>
|
||||||
|
<para>
|
||||||
|
index_next is used to display the next loop iteration. On the last
|
||||||
|
loop, this is still one more than the current index.
|
||||||
|
</para>
|
||||||
|
<example>
|
||||||
|
<title>section property index_next</title>
|
||||||
|
<programlisting>
|
||||||
|
{section name=customer loop=$custid}
|
||||||
|
{%customer.index%} id: {$customer/custid}<br>
|
||||||
|
{* FYI, $customer.index/custid and $customer/custid are identical in meaning *}
|
||||||
|
{if $customer.index_next/custid ne $customer.index/custid}
|
||||||
|
The customer id will change<br>
|
||||||
|
{/if}
|
||||||
|
{/section}
|
||||||
|
|
||||||
|
|
||||||
|
OUTPUT:
|
||||||
|
|
||||||
|
0 id: 1000<br>
|
||||||
|
The customer id will change<br>
|
||||||
|
1 id: 1001<br>
|
||||||
|
The customer id will change<br>
|
||||||
|
2 id: 1002<br>
|
||||||
|
The customer id will change<br>
|
||||||
|
|
||||||
|
</programlisting>
|
||||||
|
</example>
|
||||||
|
</sect3>
|
||||||
|
<sect3>
|
||||||
|
<title>first</title>
|
||||||
|
<para>
|
||||||
|
first is set to true if the current section iteration is the first
|
||||||
|
one.
|
||||||
|
</para>
|
||||||
|
<example>
|
||||||
|
<title>section property first</title>
|
||||||
|
<programlisting>
|
||||||
|
{section name=customer loop=$custid}
|
||||||
|
{if %customer.first%}
|
||||||
|
<table>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<tr><td>{%customer.index%} id:
|
||||||
|
{$customer/custid}</td></tr>
|
||||||
|
|
||||||
|
{if %customer.last%}
|
||||||
|
</table>
|
||||||
|
{/if}
|
||||||
|
{/section}
|
||||||
|
|
||||||
|
|
||||||
|
OUTPUT:
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<tr><td>0 id: 1000</td></tr>
|
||||||
|
<tr><td>1 id: 1001</td></tr>
|
||||||
|
<tr><td>2 id: 1002</td></tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
</programlisting>
|
||||||
|
</example>
|
||||||
|
</sect3>
|
||||||
|
<sect3>
|
||||||
|
<title>last</title>
|
||||||
|
<para>
|
||||||
|
last is set to true if the current section iteration is the last
|
||||||
|
one.
|
||||||
|
</para>
|
||||||
|
<example>
|
||||||
|
<title>section property last</title>
|
||||||
|
<programlisting>
|
||||||
|
{section name=customer loop=$custid}
|
||||||
|
{if %customer.first%}
|
||||||
|
<table>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<tr><td>{%customer.index%} id:
|
||||||
|
{$customer/custid}</td></tr>
|
||||||
|
|
||||||
|
{if %customer.last%}
|
||||||
|
</table>
|
||||||
|
{/if}
|
||||||
|
{/section}
|
||||||
|
|
||||||
|
|
||||||
|
OUTPUT:
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<tr><td>0 id: 1000</td></tr>
|
||||||
|
<tr><td>1 id: 1001</td></tr>
|
||||||
|
<tr><td>2 id: 1002</td></tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
</programlisting>
|
</programlisting>
|
||||||
</example>
|
</example>
|
||||||
</sect3>
|
</sect3>
|
||||||
@@ -1821,7 +1949,7 @@ OUTPUT:
|
|||||||
</informaltable>
|
</informaltable>
|
||||||
<para>
|
<para>
|
||||||
fetch allows the template designer to fetch files from the local
|
fetch allows the template designer to fetch files from the local
|
||||||
file system, ftp, or http, and display the contents. If the file
|
file system, http, or ftp and display the contents. If the file
|
||||||
name begins with "http://", the web site page will be fetched and
|
name begins with "http://", the web site page will be fetched and
|
||||||
displayed. If the file name begins with "ftp://", the file will be
|
displayed. If the file name begins with "ftp://", the file will be
|
||||||
fetched from the ftp server and displayed. For local files, the full
|
fetched from the ftp server and displayed. For local files, the full
|
||||||
@@ -1835,9 +1963,10 @@ OUTPUT:
|
|||||||
<para>
|
<para>
|
||||||
TECHNICAL NOTE: This function may be a security concern if you are
|
TECHNICAL NOTE: This function may be a security concern if you are
|
||||||
allowing third parties to modify templates. i.e., they can access
|
allowing third parties to modify templates. i.e., they can access
|
||||||
arbitrary files on your system. Be sure to <link
|
files on your system out side of the template directory. To disable
|
||||||
linkend="api.unregister.function">unregister</link> this function if
|
this function, <link
|
||||||
required.
|
linkend="api.unregister.function">unregister</link> it in your
|
||||||
|
application.
|
||||||
</para>
|
</para>
|
||||||
<example>
|
<example>
|
||||||
<title>fetch</title>
|
<title>fetch</title>
|
||||||
|
Reference in New Issue
Block a user