【问题标题】:Zencart - How can I set a theme/template programmatically?Zencart - 如何以编程方式设置主题/模板?
【发布时间】:2013-07-30 06:02:51
【问题描述】:
我正在尝试根据设备浏览器选择特定模板。我正在使用来自http://www.mobileesp.com 的 Anthony Hand 的库来检测设备,然后我想以编程方式设置模板。图书馆就是这样工作的
require_once 'mdetect.php';
//Instantiate the object
$uagent_obj = new uagent_info();
//Detect iPhone
if ($uagent_obj->DetectTierIphone() == $uagent_obj->true) {
echo '<!-- Setting Theme for Smart devices -->';
}
//Detect All Other Mobile Devices
else if ($uagent_obj->DetectTierOtherPhones() == $uagent_obj->true) {
echo '<!-- Setting Theme for Smart devices -->';
}
请指导我如何在 ZenCart 中做到这一点?
【问题讨论】:
标签:
themes
smartphone
zen-cart
【解决方案1】:
我找到了一个解决方案,不知道它是否符合标准。原因可能是我找不到任何设置模板的钩子。我所做的是将脚本插入到位于~/includes/init_includes/init_templates.php 的init_templates.php 文件中,就在$template_dir 的定义之后
require_once 'mdetect.php'; //set the path of file according to your folder structure. The link to mdetec script is given in the question detail.
//Instantiate the object
$uagent_obj = new uagent_info();
//Detect iPhone
if ($uagent_obj->DetectTierIphone() == $uagent_obj->true) {
$template_dir = 'iphonetemplate';
}
//Detect All Other Mobile Devices
else if ($uagent_obj->DetectTierOtherPhones() == $uagent_obj->true) {
$template_dir = 'mobiletemplate';
}
要完美运行此程序,模板必须放在您的templates 目录中。这些大多位于~/includes/templates/<template_name>
【解决方案2】:
模板在 MySQL 表 template_select 中定义,并在断点 110 处读取(根据 include/auto_loaders/config.core.php)。您应该在此断点之前定义以下常量以覆盖它:
- DIR_WS_TEMPLATE
- DIR_WS_TEMPLATE_IMAGES
- DIR_WS_TEMPLATE_ICONS
- 并设置变量 $template_dir
有关更多信息,请查看文件“includes/init_includes/init_templates.php”。