首页 > 解决方案 > 如何在 Prestashop 1.7 的移动设备中显示代码

问题描述

我需要在 Prestashop 1.7 中添加一个自定义代码,仅用于移动访问。Css display none 不是我正在寻找的解决方案。在以前的 PS 1.6 中,有效的代码是 {if $isMobile} 并检查 PS 1.7 文件 classes/Context.php 还包含变量“isMobile”。

我尝试在 .tpl 文件中添加 {if $isMobile} 或 {if $mobile_device} 但它不起作用

标签: prestashop-1.7

解决方案


在控制器模块的getWidgetVariables()函数中,您可以将以下行添加到返回的数组中:

'mobile_device' => Context::getContext()->isMobile(),

并检查您的 .tpl:

{if isset($mobile_device) && $mobile_device}
 <p>Displayed only on mobile</p> 
{/if}

推荐阅读