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

标签 php if-statement smarty responsive prestashop-1.7

我想要以下内容:

& 我知道我必须从 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}

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

另外IF条件写的对不对,这段代码要改什么?

这是 .TPL 文件。

最佳答案

尝试:

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

问候

关于php - 如何在 TPL 文件中的 prestashop 1.7 中检测 smarty 中的设备?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56275172/

相关文章:

php - 使用学生 ID mysql 和 php 创建登录页面

python - 名称错误 : free variable 'd' referenced before assignment in enclosing scope

c++ - 正确关闭 while(cin.good()) 循环

javascript - 无法弄清楚如何返回正确的数组

PHP Inner Join,当一个表有多个输出时使用foreach循环

php - 调整由 CDN 提供的 CKEditor 的大小

php - mysql在PHP中选择不同的查询

python - Jinja2 模板中的 "eval"语句

templates - 在 Smarty 中扩展基本模板

php - Smarty 删除最后一个字符后的所有内容