![](/img/trans.png)
[英]How to edit the link of a variable in opencart register.tpl file?
[英]How to get the current url in a OpenCart .tpl file?
我想在 OpenCart 的 .tpl 文件中獲取當前 url。
我見過這個答案,但它只適用於 php 文件。
我必須這樣:
_my_array.push(['_productName',"<?php echo $heading_title; ?>"]);
**_my_array.push(['_productUrl', ["how can I get url ?"]]);**
謝謝
獲取完整網址
<?php
$url = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
?>
順便說一句,這些答案也適用於 tpl 文件,因為 tpl 文件只是一種 php 文件
最佳做法是將其放入控制器中,然后在視圖文件中使用它。
在您的控制器中
$data['current'] = $this->url->link($this->request->get['route'], '', 'SSL');
然后在視圖文件中
echo $current;
我還需要 schema.org 的當前 url。
通常您可以通過鏈接功能創建當前網址
public function link($route, $args = '', $secure = false)
因此,產品頁面的 https 鏈接將是
$data['share'] = $this->url->link('product/product', 'product_id=' . (int)$this->request->get['product_id'], true);
然后在視圖文件中
echo $share
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.