Home >Backend Development >PHP Tutorial >smarty template partial caching example tutorial

smarty template partial caching example tutorial

WBOY
WBOYOriginal
2016-07-25 08:53:09977browse
  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.



Statement:
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