OpenCart pass variable to twig from controller

2019-08-26 18:52发布

Hy!

I need to use some data in twig files, how do I pass it from header.php to twig files? I created a new element in $data array, but It doesn't exist in the twig files.

$data['testvar'] = "test string";

And I try to access it in twig files like this:

{{ testvar }}

2条回答
聊天终结者
2楼-- · 2019-08-26 19:14

After you made some changes, you must in admin dashboard refresh your modifications and clear cache, blue gear icon in right upper corner.

查看更多
Summer. ? 凉城
3楼-- · 2019-08-26 19:19

If you add $data['testvar'] = "test string"; only in catalog/controller/common/header.php, than you can use {{ testvar }} only in catalog/view/theme/Your theme (or default)/template/common/header.twig.


To be sure what $data is communicate to view file, you can add die(print_r($data)); before load view.

查看更多
登录 后发表回答