prestashop-1.7 - 如何在 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} 但它不起作用
解决方案
在控制器模块的getWidgetVariables()
函数中,您可以将以下行添加到返回的数组中:
'mobile_device' => Context::getContext()->isMobile(),
并检查您的 .tpl:
{if isset($mobile_device) && $mobile_device}
<p>Displayed only on mobile</p>
{/if}
推荐阅读
- javascript - 检测评论在插件评论 zalo 中创建/删除
- python - Selenium 使用 .find 方法返回空列表,即使有项目
- stata - Stata条形图多种模型
- javascript - TypeError:无法读取未定义的属性“地图”......如何获取单个帖子
- javascript - 交换一个数组元素并移动其余元素
- environment-variables - 在 Vercel 上部署 nextjs 应用程序后,登录和注册功能不起作用
- javascript - 通过 whatsapp api 共享文件
- java - 表达式1 = 表达式2 = 表达式3 在Java 中的意义?
- android - 如何在android工具栏中的第一条垂直线下方的垂直第二行中删除主页返回箭头间距
- powerbi - 根据累积数据计算每日消耗量的 DAX 公式 - Power BI