Jump to content

How to get the full URL of current page in Smarty?


KoalaBear

Recommended Posts

Hello, I've tried every solution posted all over the Internet but with no luck, so please give me a hint.

 

I want to display the full URL from the current page in my Smarty tpl files. I am using Prestashop 1.6

 

So far I tried with tens of methods, for example {$request} or {$request_uri}, but I am not achieving the desired result.

 

I want to get the full address, for example:

 

my-website/22-category#/page-2

 

But even if I am on pagination or sorting, I managed to display only the main URL, for ex.:

 

my-website/22-category

 

Any help will be much appreciated :)

Link to comment
Share on other sites

Generally whatever comes after "#" in a url is only client-side readable. That means that server has no idea about this. So $request returns you correctly what the url asked before sorting/pagination.  If you want to access this information you should use javascript and get what you need. For example when you click for sorting, call a javascript method and read the url from the browser and show it to the. tpl file. Smarty can't help you here.

Link to comment
Share on other sites

Generally whatever comes after "#" in a url is only client-side readable. That means that server has no idea about this. So $request returns you correctly what the url asked before sorting/pagination.  If you want to access this information you should use javascript and get what you need. For example when you click for sorting, call a javascript method and read the url from the browser and show it to the. tpl file. Smarty can't help you here.

 

Thank you for your answer, but unfortunately JS is not an option. I need to get it done via Smarty or PHP. Any other suggestions will be much appreciated :(

Link to comment
Share on other sites

In prestashop 1.7, on my product.tpl i'm doing something like {$node.link} to get my url 

 

Or you could do something like

 

 $current_url = $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; 

 

I have extended my FrontController.php in order to get a custom Smarty variable, like {$current_url}, but I am still not able to obtain the actual URL even through PHP.

 

I've tried:

$_SERVER['REQUEST_URI'];

$_SERVER['QUERY_STRING'];

$_SERVER['HTTP_REFERER'];

 

etc.

 

But I can obtain only the main URL, not the query string like #/page-2, or #/category

 

$_SERVER['PHP_SELF']; is returning /index.php no matter what page I am browsing.

Edited by KoalaBear (see edit history)
Link to comment
Share on other sites

I have extended my FrontController.php in order to get a custom Smarty variable, like {$current_url}, but I am still not able to obtain the actual URL even through PHP.

 

I've tried:

$_SERVER['REQUEST_URI'];

$_SERVER['QUERY_STRING'];

$_SERVER['HTTP_REFERER'];

 

etc.

 

But I can obtain only the main URL, not the query string like #/page-2, or #/category

 

$_SERVER['PHP_SELF']; is returning /index.php no matter what page I am browsing.

Sorry to not help more then.. But i also think you should use Js for that.

You should try to post this on StackOverflow, they might help you more there 

Edited by Martin Fabre (see edit history)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...