问题
How can I use the id of a page in a Opencart template to show content only for that specific page? Or something similar?
Thanks so much Mark
回答1:
For Product.tpl
product_id
For Category.tpl
path
For Content.tpl
information_id
Edit those .tpl files and use the variables I have stated. You can use in practice in the .tpl files like:
<?
if(isset($_GET["product_id"])==""){
// yes
} else {
// do something else
}
?>
For security. You can use mysql_escape_string();
You can also use the library in certain instances. Example in Content.tpl which I believe is the issue you want. I recommend against changes like this. Make modules or better logic.
Also, $_GET can be replaced.
Note that $this->request->get
and $_GET
are the same, however OpenCart can and usually does change values in $this->request->get
after the page load for things like the route key value when using SEO keywords, therefore its advisable to use that instead of $_GET
instead of $_GET
. It also has the values cleaned to prevent any malicious values. (Reference Jay: Opencart: How to include a script on certain pages?)
来源:https://stackoverflow.com/questions/17375445/how-to-use-page-id-in-opencart