smarty template partial caching example tutorial

WBOY
Release: 2016-07-25 08:53:09
Original
950 people have browsed it
  1. require('smarty.class.php');
  2. $smarty = new smarty;
  3. $smarty->caching = true;
  4. function smarty_block_dynamic($param, $content, &$smarty) {
  5. return $content;
  6. }
  7. $smarty->register_block('dynamic', 'smarty_block_dynamic', false);
  8. $smarty->display('index.tpl');
Copy code

index.tpl Template file:

  1. page created: {"0"|date_format:"%d %h:%m:%s"}

  2. {dynamic}
  3. now is: {"0"|date_format:" %d %h:%m:%s"}
  4. ... do other stuff...

  5. {/dynamic}

Copy code

When this page is reloaded, you will notice that the two dates are different. One is "dynamic" and the other is "static". You can do anything between {dynamic}...{/dynamic} and be sure it won't be cached like the rest of the page.

The above is an example of partial caching of smarty templates. I hope it will be helpful to everyone.



source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!