Current Controller name in Prestashop template using Smarty reserved variable

How to get Current Controller name in Prestashop template?

To get Current Controller name in Prestashop template, you just have to study some smarty variable. Click here to know more about Reseverd smarty variables.

See url structure of prestashop, some of data passed through GET method.

E.g. http://prestashopExample.com/index.php?id_category=4&controller=category&id_lang=1

In above example, we can see Controller category is passed though Get Method. Prestashop uses Smarty template engine for views. Designer or developer working on template can only use PHP code, if allowed. To get data passed through URL see below example taken from documentation of Smarty.

{* display value of page from URL ($_GET) http://www.example.com/index.php?page=foo *}
{$smarty.get.page}

{* display the variable "page" from a form ($_POST['page']) *}
{$smarty.post.page}

I think You are now clear about what to do,

To display controller name from URL ($_GET) http://prestashopExample.com/index.php?id_category=4&controller=category&id_lang=1

{$smarty.get.controller}

Or you can assign a variable to store name of controller

{assign var='controllerName' value=$smarty.get.controller}

& can use for different purpose, Like  to print

{$controllerName}

, to compare

{if $controllerName == 'cms'} condition{/if}

This is very simple trick I used while working first time on Prestashop. You can use this trick to create different template looks in prestashop using controller name.

Please make comments if you have any queries and share & give feedback if you have found useful.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top