Opencart:如何在某些页面上包含脚本? [英] Opencart: How to include a script on certain pages?

查看:74
本文介绍了Opencart:如何在某些页面上包含脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想包含一个脚本来检测站点某些页面上的$_GET值.如果我在header.tpl中使用脚本,它将在所有页面上添加脚本.如果我将其用作模板文件并在扩展>模块中将其显示为Layout,它将被添加到该布局内的所有页面.是否有办法仅在某些选定页面上包括此内容?我敢肯定,这将必须以编程方式完成.只是想了解是否有一种优雅的方法可以做到这一点.

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.

推荐答案

您可以在任何控制器,模型或视图文件中使用正确的$this->request->get方法访问$_GET文件.至于一个优雅的解决方案,这实际上取决于您要显示在哪些页面上,以及页面的哪个区域.例如,如果您只想在产品页面上使用代码,但想在标题中放置代码,则需要在index()header.php控制器中检查路由为product/product.方法,然后使用$this->data['your-variable'] = $some_data;将数据传递到模板.同样,在使用product.php控制器的产品页面上,这几乎是相同的,因为跳过了路由检查,因为该控制器只会在产品页面上调用

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

这篇关于Opencart:如何在某些页面上包含脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆