在Prestashop 1.6站点中,我需要向body元素添加一个动态类(就在前面)。
类应该是‘组-组-名- id’,其中组名-id是访问者的组名id。
Presashop中的默认组是:
“1”--“来访者”
“2”--“客人”
“3”--“顾客”
有办法这样做吗?
我发现了这一点,但似乎已经过时了,因为它适用于PS1.4:https://www.prestashop.com/forums/topic/179593-adding-category-class-id-to-product-page-body/

更新:
多亏了@TheDrot的回答(就在下面),我几乎就能得到它。
唯一的问题是:我得到了这个错误:第36行/home/temporal-4/www/override/classes/controller/FrontController.php中的"Parse :语法错误,意外的'[',期待')‘“。
如果我删除'‘,它可以工作,但在类中,我得到“组数组”。我需要打印数组的所有值,如class=“组-1组-2组-3”。
发布于 2016-05-05 12:43:56
您需要覆盖FrontControllerCore类,因此在文件夹‘FrontController.php / class /控制器/’中创建一个文件,并放入下面的代码
class FrontController extends FrontControllerCore {
public function init()
{
parent::init();
$this->context->smarty->assign('group_id', $this->context->customer->getGroups()[0]; // user can exist in multiple groups, so for this example im just grabbing first group id
}
}然后在“themes/your/”中打开header.tpl文件,并向body类添加代码
group-{$group_id}如果在body类中只看到组,请确保从缓存文件夹中删除class_index.php并重新加载页面。
发布于 2021-09-07 11:34:59
对于PS1.7,不需要覆盖任何东西,也许它适用于PS1.6
添加$groupid = "group-1“或"group-2”等。要通过在控制器和模板中使用add ()函数来实现智能参数,请在顶部添加
{$page["body_classes"][$groupid] = 'true'}让我们知道这个把戏
https://stackoverflow.com/questions/37049485
复制相似问题