PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, June 28, 2022

[FIXED] How to detect device in smarty in prestashop 1.7 in a TPL file?

 June 28, 2022     if-statement, php, prestashop-1.7, responsive, smarty     No comments   

Issue

I want the following:

& I understand I have to take the codes from context.php of PrestaShop but I seem to be making an error. A link to getcontext is as follows: (The code to detect mobile device is here) https://github.com/PrestaShop/PrestaShop/blob/develop/classes/Context.php

{if isset($products) AND $products}
             {$tabname=rand()+count($products)}
            {if isset($display_mode) && $display_mode == 'carousel'}
                {include file="{$items_owl_carousel_tpl}" items=$products image_size=$image_size}
            {else}
                {if device is MOBILE} /* Correct Code Needed */
                    {include file="{$items_normal_tpl}" items=$products image_size="homepage_default"}
                {else device is NOT MOBILE} /* Correct Code Needed */
                    {include file="{$items_normal_tpl}" items=$products image_size="home_default"}
                {/if}
            {/if}
        {/if}

What codes should I enter in the IF condition to make sure it detects mobile and not mobile.

Also is the IF condition written properly, what should I change in this code?

This is .TPL File.


Solution

try with :

{if Context::getContext()->isMobile() == 1}
    {if Context::getContext()->getDevice() != 2}
        // TABLETTE
    {else}
        // MOBILE
    {/if}
{else}
    // PC
{/if}

Regards



Answered By - ethercreation
Answer Checked By - Timothy Miller (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

1,261,705

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © 2025 PHPFixing