Jump to content

If Variable for Mobile Theme?


Recommended Posts

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

  • Like 1
Link to comment
Share on other sites

  • 4 months later...
  • 3 weeks later...
  • 11 months later...

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?  

  • Like 1
Link to comment
Share on other sites

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. :)

  • Like 5
Link to comment
Share on other sites

  • 2 months later...
  • 4 months later...

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

  • 8 months later...

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

  • 1 month later...

 

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}
 
:)

 

:(  :unsure:  :wacko: 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.

:rolleyes:

  • Like 1
Link to comment
Share on other sites

  • 1 year later...
  • 4 months later...
  • 6 months later...
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

  • 1 year later...
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

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

  • 6 months later...

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

  • 5 months later...

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 by arafatx (see edit history)
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...