How Smarty works

Compiling

Smarty compiles the templates into native PHP code on-the-fly. The actual PHP scripts that are generated are created implicitly, so theoretically you should never have to worry about touching these files, or even know of their existence. The exception to this is debugging Smarty template syntax errors, discussed later in this document.

Caching

Smarty can cache the output of your generated templates. By default this is disabled. If you enable caching, Smarty will store a copy of the generated template output, and use this until the copy expires, regenerating a new one. The default cache expire time can be configured from the class. The exception to the rule is the insert tag. Anything generated by the insert tag is not cached, but run dynamically on every invocation, even within cached content.

Technical Note: Any time you change a template, change values in config files or change the content that gets displayed in a template, you can turn on compile_check to regenerate the caches that are affected, or wait for the cache to expire to see the results of the changes. You clear caches manually by deleting files from the cache directory, programatically with clear_cache or clear_all_cache, or turn on $compile_check (or $force_compile).

Technical Note: As of Smarty 1.4.6, if you have caching enabled AND you have compile_check enabled, the cached file will regenerate if an involved template or config file has been modified, regardless of the cache expire time. This results in a slight performance hit since it has to check the templates and config files for modification times. Therefore if you are not actively changing templates or config files, it is advisable to leave compile_check off. As of Smarty 1.4.7, enabling $force_compile will cause cache files to always be regenerated.