I'd like to get the current url in a .tpl file in OpenCart.
I've seen this answer but it works only in a php file.
I have to get this way:
_my_array.push(['_productName',"<?php echo $heading_title; ?>"]);
**_my_array.push(['_productUrl', ["how can I get url ?"]]);**
Thanks
To get full url
<?php
$url = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
?>
and btw those answers work on tpl files also because tpl files are sort of php files only
The best practice would be to get it in the controller then use it in the view file.
In your controller
$data['current'] = $this->url->link($this->request->get['route'], '', 'SSL');
Then in the view file
echo $current;
I also needed current url for schema.org.
Generally you can create current url via link function
public function link($route, $args = '', $secure = false)
So https link for product page that would be
$data['share'] = $this->url->link('product/product', 'product_id=' . (int)$this->request->get['product_id'], true);
Then in the view file
echo $share
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.