如何在TPL文件中的prestashop 1.7中检测smarty中的设备?

Arp*_*ain 3 php if-statement smarty prestashop-1.7 responsive

我想要以下内容:

& 我知道我必须从 PrestaShop 的 context.php 中获取代码,但我似乎犯了一个错误。getcontext 的链接如下:(检测移动设备的代码在这里) 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}
Run Code Online (Sandbox Code Playgroud)

我应该在 IF 条件中输入哪些代码以确保它检测到移动设备而不是移动设备。

IF条件也写得正确,我应该在这段代码中改变什么?

这是 .TPL 文件。

小智 5

尝试:

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

问候