phpif-statementsmartyresponsiveprestashop-1.7

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


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