evolution.x Posted April 15, 2013 Share Posted April 15, 2013 Hi, Does anybody know what the correct {if} variable is for the mobile theme? I need to change some pictures which display on the mobile theme, so I was going to use "if mobile use this image"? Any help on this would be great! Link to comment Share on other sites More sharing options...
evolution.x Posted April 16, 2013 Author Share Posted April 16, 2013 Anybody? Link to comment Share on other sites More sharing options...
PascalVG Posted April 16, 2013 Share Posted April 16, 2013 There is a function in /tools/mobile_Detect/Mobile_Detect.php public function isMobile($userAgent = null, $httpHeaders = null) { , that checks if the device is mobile, but that's not exactly what you need. In classes/context.php is a test : protected function checkMobileContext() Maybe that gives some light?? My 2 cents, Pascal 1 Link to comment Share on other sites More sharing options...
evolution.x Posted April 17, 2013 Author Share Posted April 17, 2013 Thanks for your advice, it is much appreciated. I will look in to it I was hoping for something like: {if $mobile == 1} SHOW THIS IMAGE {else} SHOW THIS IMAGE {/if} Link to comment Share on other sites More sharing options...
Ray UK Posted August 23, 2013 Share Posted August 23, 2013 Not sure if you found a way around this.... But this may help you {if $PS_ALLOW_MOBILE_DEVICE}You are using a desktop{else}<p>You are using a mobile</p>{/if} Link to comment Share on other sites More sharing options...
vekia Posted August 24, 2013 Share Posted August 24, 2013 $PS_ALLOW_MOBILE_DEVICE is avariable where is stored information from preferneces > themes tab. so it's not related to the "browsed" page, just to setting defined in preferences (which inform if moble is enabled or not) Link to comment Share on other sites More sharing options...
vekia Posted September 9, 2013 Share Posted September 9, 2013 sorry for late reply, but i discovered something this if condition should work: {if isset($hook_mobile)} THIS IS MOBILE {/if} Link to comment Share on other sites More sharing options...
yassination Posted August 30, 2014 Share Posted August 30, 2014 @vekia your solution didn't work for me! Link to comment Share on other sites More sharing options...
vekia Posted August 30, 2014 Share Posted August 30, 2014 @vekia your solution didn't work for me! and where you use it and in what prestashop version ? Link to comment Share on other sites More sharing options...
yassination Posted August 31, 2014 Share Posted August 31, 2014 Thanks for your swift reply. I'm currently using Prestashop 1.6.0.6 and I was trying to use it in the header.tpl. Link to comment Share on other sites More sharing options...
vekia Posted August 31, 2014 Share Posted August 31, 2014 this is why it doesnt work. prestashop 1.6 doesnt use hook_mobile anymore, because ps 1.6 uses responsive theme, not separate mobile theme as 1.5 and 1.4 Link to comment Share on other sites More sharing options...
yassination Posted August 31, 2014 Share Posted August 31, 2014 What if I don't want certain part of my pages to load on mobile and I don't want to use bootstrap classes to hide them, I want to completely remove them on mobile. Is there any function in prestashop that can tell if a user is using a mobile device or a desktop device or should I implement my own custom functions? 1 Link to comment Share on other sites More sharing options...
yassination Posted August 31, 2014 Share Posted August 31, 2014 I couldn't find any built-in Prestashop Smarty variable that will determine if a user is on a Mobile device or a desktop device, I decided to assign my own variable in FrontController.php at the end of the __construct() method. $this->context->smarty->assign('isMobile', $this->context->getMobileDevice()); and then in your template you can use it like this: {if $isMobile} <h1>Amazing</h1> {/if} Just in case someone else might needed and doesn't want to waste time looking around. 5 Link to comment Share on other sites More sharing options...
sg1_anhell Posted November 18, 2014 Share Posted November 18, 2014 Thank you very much for this solution, yassination! Now I can do a different code for mobile versions using the same tpl files! Link to comment Share on other sites More sharing options...
Musicmind Posted April 9, 2015 Share Posted April 9, 2015 I couldn't find any built-in Prestashop Smarty variable that will determine if a user is on a Mobile device or a desktop device, I decided to assign my own variable in FrontController.php at the end of the __construct() method. $this->context->smarty->assign('isMobile', $this->context->getMobileDevice()); and then in your template you can use it like this: {if $isMobile} <h1>Amazing</h1> {/if} Just in case someone else might needed and doesn't want to waste time looking around. I´m using 1.4.10.0, exactily where insert the code? Thanks Link to comment Share on other sites More sharing options...
pmaojo Posted April 10, 2015 Share Posted April 10, 2015 Hello. I dont undestand one thing, the modules can be activated for tablet, mobile or desktop, somehow that checking occurs before content is served. Link to comment Share on other sites More sharing options...
PascalVG Posted April 10, 2015 Share Posted April 10, 2015 Hi pmaojo, See post #13: You can check on the server side using this: $this->context->getMobileDevice(); My 2 cents, pascal 1 Link to comment Share on other sites More sharing options...
Neekkola Posted December 23, 2015 Share Posted December 23, 2015 Hello I'm on 1.5 version. I'm trying to set a variable contact link for mobile users. I would like something like this : desktop user = link A mobile user = link B I see this Vekia response : this if condition should work: {if isset($hook_mobile)}THIS IS MOBILE{/if} Is this the right way ? I ignore how to set variable in my html code Could you help me please ? Link to comment Share on other sites More sharing options...
UniArt Posted February 8, 2016 Share Posted February 8, 2016 Hello, I found this already assigned variable $mobile_device in the FrontController and without changing anything I have used in the tpl and works great: {if isset($mobile_device)} THIS IS MOBILE {/if} Link to comment Share on other sites More sharing options...
UniArt Posted February 9, 2016 Share Posted February 9, 2016 Hello, I found this already assigned variable $mobile_device in the FrontController and without changing anything I have used in the tpl and works great: {if isset($mobile_device)} THIS IS MOBILE {/if} Excuse me, but it did not work as I imagined, I made a mistake, sorry. But I found in the file context.php many variables that perhaps would be useful. 1 Link to comment Share on other sites More sharing options...
chiiraz Posted April 1, 2017 Share Posted April 1, 2017 thanks for the solution! Link to comment Share on other sites More sharing options...
PepeLopez Posted August 21, 2017 Share Posted August 21, 2017 Page has js variable 'isMobile' defined, if suitable you can do your stuff through js... <script> if (isMobile === true) { ...do your stuff... } </script> Link to comment Share on other sites More sharing options...
julianbaros Posted February 28, 2018 Share Posted February 28, 2018 On 31/08/2014 at 8:29 PM, yassination said: I couldn't find any built-in Prestashop Smarty variable that will determine if a user is on a Mobile device or a desktop device, I decided to assign my own variable in FrontController.php at the end of the __construct() method. and then in your template you can use it like this: {if $isMobile} <h1>Amazing</h1> {/if} Just in case someone else might needed and doesn't want to waste time looking around. Hello, I'm on Prestashop 1.6.0.11, I'm trying to modified something when I'm in a mobile session. I correctly add in FrontController.php : $this->context->smarty->assign('isMobile', $this->context->getMobileDevice()); After that, I have modified the file nav.tpl : <!-- Block user information module NAV --> {if $is_logged} <div class="header_user_info"> <a href="{$link->getPageLink('my-account', true)|escape:'html':'UTF-8'}" title="{l s='View my customer account' mod='blockuserinfo'}" class="account" rel="nofollow"><span>{$cookie->customer_firstname} {$cookie->customer_lastname}</span></a> </div> {/if} <div class="header_user_info"> {if $is_logged} <a class="logout" href="{$link->getPageLink('index', true, NULL, "mylogout")|escape:'html':'UTF-8'}" rel="nofollow" title="{l s='Log me out' mod='blockuserinfo'}"> {l s='Sign out' mod='blockuserinfo'} </a> {else} {if $isMobile} <a class="login_mobile" href="{$link->getPageLink('my-account', true)|escape:'html':'UTF-8'}" rel="nofollow" title="{l s='Log in to your customer account' mod='blockuserinfo'}"> {l s='Mon compte' mod='blockuserinfo'} </a> {else} <a class="login" href="{$link->getPageLink('my-account', true)|escape:'html':'UTF-8'}" rel="nofollow" title="{l s='Log in to your customer account' mod='blockuserinfo'}"> {l s='Sign in' mod='blockuserinfo'} </a> {/if} {/if} </div> <!-- /Block usmodule NAV --> On my mobile phone and my laptop, my template call the same thing : login and not login_mobile ! Can you help me please ?? Link to comment Share on other sites More sharing options...
mheredia Posted July 24, 2019 Share Posted July 24, 2019 On 8/31/2014 at 1:29 PM, yassination said: I couldn't find any built-in Prestashop Smarty variable that will determine if a user is on a Mobile device or a desktop device, I decided to assign my own variable in FrontController.php at the end of the __construct() method. $this->context->smarty->assign('isMobile', $this->context->getMobileDevice()); and then in your template you can use it like this: {if $isMobile} <h1>Amazing</h1> {/if} Just in case someone else might needed and doesn't want to waste time looking around. I used it but I shuold to change the function getMobileDevice() by isMobile() in FrontController.php and is working... $this->context->smarty->assign('isMobile', $this->context->isMobile()); Thanks a lot. I'm using PS 1.7.5.1 Regards 1 1 Link to comment Share on other sites More sharing options...
Joyplaz Posted February 18, 2020 Share Posted February 18, 2020 Is anybody else getting false positives with this function? $this->context->smarty->assign('isMobile', $this->context->isMobile()); When I var_dump $isMobile in my tpl file, sometimes on desktop it shows true and on mobile (from my chrome dev tools) shows false. Then randomly after a bunch of refreshes it will work. FYI, I'm using prestashop 1.7 Link to comment Share on other sites More sharing options...
MaXi32 Posted July 19, 2020 Share Posted July 19, 2020 (edited) Can anyone shed more light to this post especially on the ps 1.7. On 2/18/2020 at 9:06 PM, Joyplaz said: Is anybody else getting false positives with this function? $this->context->smarty->assign('isMobile', $this->context->isMobile()); When I var_dump $isMobile in my tpl file, sometimes on desktop it shows true and on mobile (from my chrome dev tools) shows false. Then randomly after a bunch of refreshes it will work. FYI, I'm using prestashop 1.7 this one is working. thanks a lot Edited July 19, 2020 by arafatx (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now