Opencart: How to include a script on certain pages?

时间秒杀一切 提交于 2020-01-04 06:11:14

问题


I'd like to include a script to detect $_GET values on certain pages of the site. If I use the script in header.tpl, it will add the script on all pages. If I use it as a template file and display it as Layout in the Extensions > Modules, it gets added to all the pages within that Layout. Is there a way to include this only on certain selected pages? I'm sure this will have to done programatically. Just wanted to find out if there is an elegant way to do this.


回答1:


You can access the $_GET files using the correct method of $this->request->get in any of the controller, model or view files. As for an elegant solution, that really depends on which pages you want it to show on and also what region of the page. For example, if you only want to use code on the product pages, but want to have the code placed in the header, you would need to check for the route to be product/product in your header.php controller in the index() method, then pass the data to the template using $this->data['your-variable'] = $some_data;. Similarly, this would be almost the same on a product page using the product.php controller and skipping the route check since that controller will only be called on product pages



来源:https://stackoverflow.com/questions/16974558/opencart-how-to-include-a-script-on-certain-pages

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