How to get the current url in a OpenCart .tpl file?

15,603

Solution 1

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

Solution 2

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;

Share:
15,603
Cleyton
Author by

Cleyton

More info at my LinkedIn

Updated on July 24, 2022

Comments

  • Cleyton
    Cleyton almost 2 years

    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

  • mehov
    mehov over 4 years
    Make sure to replace '' with 'token='.$this->session->data['token'] if you need an admin URL