Sep 5, 2013

Prestashop 1.5.x Smarty Magic : Constants

Prestashop's Smarty has some hidden tricks. These constants are poorly documented. I found out the first of the list by googling, but no explanation appeared anywhere. So I decided to put this list here and maybe help other fellow programmers that are also struggling with Prestashop :-)
I will post more info about the missing ones as soon as I know about them.
  • {$smarty.const._CUSTOMIZE_TEXTFIELD_}: ???
  • {$smarty.const._CUSTOMIZE_FILE_}: ???
  • {$smarty.const._MODULE_DIR_} : will give you the module directory inside your /modules/ directory: Example of usage in the module "Homeslider" (.tpl):
    • <img src="{$smarty.const._MODULE_DIR_}/homeslider/images/{$slide.image|escape:'htmlall':'UTF-8'}" alt="{$slide.legend|escape:'htmlall':'UTF-8'}" height="{$homeslider.height|intval}" width="{$homeslider.width|intval}" /> 
  • {$smarty.const._THEME_PROD_DIR_}: Unknown.
  • {$smarty.const._THEME_PROD_PIC_DIR_}: ???
  • {$smarty.const._THEME_CSS_DIR_}: CSS dir of your theme.
  • {$smarty.const._THEME_DIR_} : will give tou the theme directory in your template (useful if you want to access your "img" folder, for example).
  • {$smarty.const._PS_THEME_MOBILE_DIR_}: Theme mobile directory: themes/yourtheme/mobile.
  • {$smarty.const._PS_ADMIN_IMG_}: /img/admin path.
  • {$smarty.const._PS_VERSION_}: Get the version number of the Prestashop installation.
  • {$smarty.const._PS_ROOT_DIR_}: Root PS installation dir. Example of usage:
    • {if file_exists($smarty.const._PS_ROOT_DIR_|cat:"/img/co/$id_value.jpg")}
  • {$smarty.const._PS_JS_DIR_}: Javascript dir inside base PS directory: /js/
  • {$smarty.const._PS_IMG_}: Prestashop /img/ folder.
  • {$smarty.const.PS_TAX_EXC}: Tax excluded?
  • {$smarty.const.PS_TAX_INC}: Tax included?
  • {$smarty.const.PHP_URL_HOST}: Base URL?
  • {$smarty.const.NULL}: NULL value, example: 
    • {assign var='productPrice' value=$product->getPrice(true, $smarty.const.NULL, 2)}

Please let me know if you know the usage or values of the ones that I don't know via comments.

I hope it helps you a bit!

See you!