Rissinko Posted June 9, 2016 Share Posted June 9, 2016 Hi, I know that in prestashop is implemented Mobile detect php class.. But I cant figure how can I detect if someone use tablet. I need use it in header.tpl file. I use this in my classes/product.php $ismobile = Context::getContext()->getMobileDevice(); But i think it is for all mobile devices. But i need one variable for tablet and one for mobile. Link to comment Share on other sites More sharing options...
rocky Posted June 11, 2016 Share Posted June 11, 2016 I just checked my PrestaShop v1.6.1.5 test site and I see the following function in classes/Context.php that you can use: Context::getContext()->isTablet(); 1 Link to comment Share on other sites More sharing options...
Rissinko Posted June 11, 2016 Author Share Posted June 11, 2016 Thanks rocky! I don't know why I didnot check that context .php file before.. .. Link to comment Share on other sites More sharing options...
ibouchta Posted July 27, 2018 Share Posted July 27, 2018 Hello how to use this variable in TPL please i need to make if mobile (ok) else (no) /if regards Link to comment Share on other sites More sharing options...
rocky Posted July 28, 2018 Share Posted July 28, 2018 PrestaShop v1.6 has the $mobile_device variable available to TPL files: {if $mobile_device}OK{else}NO{/if} That won't work for tablet detection though. You could try the following for it: {if Context::getContext()->isTablet()}OK{else}NO{/if} 1 Link to comment Share on other sites More sharing options...
ms_hassan Posted February 7, 2020 Share Posted February 7, 2020 In your php file you can write following and pass it to tpl. {file_name}.php $this->context->smarty->assign(array( 'is_mobile' => Context::getContext()->isMobile(), 'device_type' => Context::getContext()->getDevice(), )); ---------------------------------------------------- In your tpl file you can use it like this. {file_name}.tpl {if isset($is_mobile) && $is_mobile == 1} <div class="for_mobile">MOBILE</div> {else} <div class="for_other_devices">---</div> {/if} NOTE: getDevice() returns 1,2,4 for device types const DEVICE_COMPUTER = 1; const DEVICE_TABLET = 2; const DEVICE_MOBILE = 4; 1 1 Link to comment Share on other sites More sharing options...
Butch0071 Posted May 19 Share Posted May 19 {if Context::getContext()->isMobile() && !Context::getContext()->isTablet()} your content {/if} 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