2016-05-05 28 views
0

在Prestashop 1.6站點中,我需要爲正文元素(僅在前端)添加動態類。Prestashop 1.6 - 如何將動態類添加到正文元素

該類應該是'group- [group-name-id]',其中group-name-id是訪問者的組名。在Presashop

默認組是:

'1' - '訪問者'

'2' - '旅客'

'3' - '負荷消費'

有沒有辦法做到這一點?

我發現這一點,但似乎已經過時,因爲它是PS 1.4:https://www.prestashop.com/forums/topic/179593-adding-category-class-id-to-product-page-body/

enter image description here

UPDATE:

我幾乎把它歸功於@TheDrot答案(略低於)。

唯一的問題是這樣的:[0]。我得到這個錯誤:「解析錯誤:語法錯誤,意想不到'[',期待')'在/ home/tempporal_4/www/override/classes/controller/FrontController.php在36行」。

如果我刪除'[0]'它可以工作,但然後在課堂上我得到「組數組」。我需要打印所有數組的值,如class =「group-1 group-2 group-3」。

回答

1

你需要重寫FrontControllerCore類,以便創建文件夾中的文件FrontController.php「覆蓋/班/控制器/」,並把這個代碼

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 
    } 
} 

然後打開header.tpl文件「主題/ your_theme /」和體類

group-{$group_id} 

添加代碼,如果身體類,你只能看到組 - ,一定要刪除緩存文件夾class_index.php並重新加載頁面。

+0

在文件'FrontController.php'我已經有這樣的代碼:http://pastebin.com/raw/bm9yY3TT你能告訴我在哪裏插入你的代碼在數組中?謝謝。 – chefnelone

+0

無論你在哪個數組中放置它,都沒關係。你所要做的就是將'group_id'=> $ this-> context-> customer-> getGroups()[0]添加到數組中。 – TheDrot

+0

我剛剛做到了。我在這裏複製並粘貼了代碼:http://pastebin.com/raw/ZuCUdpyQ您可以在數組的最後位置看到它。但現在,我在我的網站中收到了一個500錯誤的empy頁面。 – chefnelone