diff --git a/FAQ b/FAQ index 494b92df..956fe8fd 100644 --- a/FAQ +++ b/FAQ @@ -38,26 +38,24 @@ 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. 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. - +A: It could be. One of the strengths of Smarty is that it does not need to + parse the template files on every hit to the server. Version 1.3.1 has + many noticable performance tune-ups, so your best bet is to try some + benchmarks and compare for yourself. + 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. + unfair since Smarty will basically be displaying static content instead of + 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? A: Certainly. You might want to change your tag delimiters from {} to something that resembles valid HTML, like or <{ }> or something similar. diff --git a/NEWS b/NEWS index f3dd69e5..6e4b259e 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,8 @@ + - document first, last, index_prev, index_next (Monte) - added 'first' and 'last' section properties. (Andrei) - split out compiling code to separate class for faster template execution time (Monte) + - fixed a couple of minor PHP warnings (Monte) - added and documented unregister_modifier() and unregister_function() API calls. (Monte) - added and documented 'fetch' and 'math' functions. (Monte) diff --git a/docs.sgml b/docs.sgml index b75a1410..e20d3350 100644 --- a/docs.sgml +++ b/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} // or, {date_now format="%Y/%m/%d"} to format it. + + + + + clear_cache + + + void clear_cache + string template + string cache id + + + + 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 + caching section for more + information. This was added to Smarty 1.3.0. + + +clear_cache + + +// 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"); + + + + + + + clear_all_cache + + + void clear_all_cache + + + + + This clears the entire template cache. This was added to Smarty + 1.3.0. + + +clear_all_cache + + +// clear the entire cache +$smarty->clear_all_cache(); + + @@ -653,59 +706,6 @@ $smarty->register_modifier("sslash","stripslashes"); $smarty->unregister_modifier("strip_tags"); - - - - - clear_cache - - - void clear_cache - string template - string cache id - - - - 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 - caching section for more - information. This was added to Smarty 1.3.0. - - -clear_cache - - -// 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"); - - - - - - - clear_all_cache - - - void clear_all_cache - - - - - This clears the entire template cache. This was added to Smarty - 1.3.0. - - -clear_all_cache - - -// clear the entire cache -$smarty->clear_all_cache(); - - @@ -1646,6 +1646,134 @@ OUTPUT: 1 id: 1001<br> 2 id: 1002<br> + + + + + index_prev + + index_prev is used to display the previous loop iteration. + on the first loop, this is set to -1. + + +section property index_prev + +{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> + + + + + + index_next + + index_next is used to display the next loop iteration. On the last + loop, this is still one more than the current index. + + +section property index_next + +{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> + + + + + + first + + first is set to true if the current section iteration is the first + one. + + +section property first + +{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> + + + + + + last + + last is set to true if the current section iteration is the last + one. + + +section property last + +{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> + @@ -1821,7 +1949,7 @@ OUTPUT: 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 displayed. If the file name begins with "ftp://", the file will be fetched from the ftp server and displayed. For local files, the full @@ -1835,9 +1963,10 @@ OUTPUT: TECHNICAL NOTE: This function may be a security concern if you are allowing third parties to modify templates. i.e., they can access - arbitrary files on your system. Be sure to unregister this function if - required. + files on your system out side of the template directory. To disable + this function, unregister it in your + application. fetch