Sunday, January 15, 2012

PrestaShop Tips - How to disable your PrestaShop smarty cache restaShop

This post is an introduction to PrestaShop smarty cache. This is a tip for a beginner PrestaShop owner or developer.

Basic information about Smarty
Smarty is PHP template engine, with smarty, you are able to separate business/program logic from your GUI design(theme or template). PrestaShop utilize smarty engine so that you are able to switch/change your PrestaShop theme easily. The theme files (GUI design) are saved in separated themes folder, and with .tpl file extension.

For example (PrestaShop standard theme)
YourStoreRoot/themes/prestashop/header.tpl
YourStoreRoot/themes/prestashop/footer.tpl
...

But in order to make your theme file work, it has to be compiled into native PHP file before your web server can render page HTML contents to your browser client. Compiling the themes file will reduce your server performance. In order to minimize the performance influences, PrestaShop uses smarty function so that the compilation is done only at first time of usage of theme file.

Potential issues
As mentioned above, when smarty cache is turned on, the compilation will only be done at first time use of the theme file. That means when you make changes on the theme file, the new change you applied to the theme file will not be in effect.

By default, the smarty cache is turned on after you install your PrestaShop. If you do not know there is a smarty cache is in action, you may not know why your changes on theme file does not reflect to your PrestaShop pages. If you want to make changes and test the changes, you will have to turn off the smarty cache temporary.

How to turn off or turn on smarty cache

PrestaShop 1.3x or lower

To switch smarty cache in PrestaShop 1.3x or lower, you need to change following two lines in smarty configuration file as listed below

Configuration file location:
YourStoreRoot/config/smarty.config.inc.php

To turn off, change lines to
(when your make changes on your store theme files)

$smarty->caching = false;
$smarty->force_compile = true;


To turn on, change lines to
(when your store is in production mode, no changes will be made)

$smarty->caching = true;
$smarty->force_compile = false;

PrestaShop 1.4x or higher
If you are using PrestaShop 1.4x or higher, you don't need to changes file directly, you can make changes from you back office directly.

log in to your back office
click Preferences tab
click Performance tab
switch the smarty cache on or off and click "Save" button"


Recommended setting of smarty cache

It is highly recommend to leave your smarty cache on if your store is in production or you are not making any changes to any themes files. This will rapidly improveyour store performances.

1 comment:

Palmer Scott said...
This comment has been removed by a blog administrator.