Blog navigation keyboard_arrow_down

Blog Rss rss_feed

Global variable in smarty to define the phone

Global variable in smarty to define the phone

In some cases, it is important to know that the person comes from the phone. This will allow the user to download certain content without unnecessary information, which will increase the speed of page loading and increase the level of user involvement.

In PrestaShop 1.7 there is no global variable that defines a mobile phone, so in this article I would like to tell you how to add it.

To start in the classes folder on the path

/override/classes/

Create a FrontController file.php, thereby redefining the core class and then adding a method

protected function assignGeneralPurposeVariables()

It will include our new variable

'is_mobile' => Context::getContext()->isMobile(),

It is set to false or true depending on the type of device (the latter is a mobile phone).

After the changes, be sure to update the cache. Congratulations! Now you can call our new variable anywhere in the template

 { $is_mobile }

Was this blog post helpful to you?

    
No comments at this moment
close

Checkout

close

Favourites