Welcome to my personal webspace...

I'm a webmaster living in Manchester and I specialise in user interface and user experience design, although I do like front-end development too. One day you can see me designing user-focused web interface for e-commerce client, the other I could be developing it using XHTML, CSS, JavaScript libraries (like jQuery) and progressive enhancement approach. So take a look at my work, maybe you'll find something nice to look at. And don't forget to subscribe to my RSS feed top get the latest headlines!

July 24 2009

SMARTY globals in PrestaShop uncovered

globals_banner

Many designers and developers who encountered PrestaShop are impressed by the features, easiness in creating new themes and complete scalable structure which allows us to PrestaShop modules and other add-ons. It’s all easy when we want to do something simple, but when the code is getting tricky and it’s starting to be hard to distinguish different pieces of code we can make a simple mistake that will throw our module out of the window. But here comes SMARTY with its templating system which processes the back-end content and makes the output available for the front-end to be displayed.

But how we can use it in PrestaShop? This is easy, there are loads of variables available for every single page that is being loaded. For the purpose of this article we will call them SMARTY Globals. They gather most important content/info from the back end and throws it into the memory allowing us to use them however we want. So here you will find a comprehensive list of variables/globals that you can use within PrestaShop without any modules. Each file/page loads their own variables so for now I will cover only the globals.

$base_dir { root folder of your shop }
$base_dir_ssl { root folder of your shop using HTTPS protocol }
$content_dir { root folder of your shop depending on the SSL settings }
$img_ps_dir { root folder containing images "/img/" }
$img_dir { images folder in your current theme directory }
$css_dir { css folder inside the current theme folder }
$js_dir { JavaScript inside the theme folder }
$tpl_dir { theme root folder }
$modules_dir { modules root folder }
$mail_dir { mail templates root folder }
$lang_iso { current language ISO code }
$come_from { previous page address [absolute] }
$shop_name { your specified shop name }
$cart_qties { total number of products in the cart }
$cart { shopping cart contents }
$currencies { pulls available currencies }
$id_currency_cookie { selected currency id [cookie dependent] }
$currency { active currency }
$cookie { active cookie }
$languages { grabs available languages }
$logged { checks whether users is logged in }
$page_name { current page's name }
$customerName { customer name [session dependent] }
$priceDisplay { current price display settings [currency dependent] }

These globals are available from any page within the shop as the init.php file is being loaded with every page, so you don’t have to worry about not being able to use one or two of them. If you have any questions or require more explanation, include them in your comments and I will do my best to sort this out.

Comments:

(2) posted on SMARTY globals in PrestaShop uncovered

Post a comment