OpenCart pass variable to twig from controller

折月煮酒 提交于 2019-12-11 18:14:07

问题


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

回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/52465396/opencart-pass-variable-to-twig-from-controller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!