KoalaBear Posted May 18, 2017 Share Posted May 18, 2017 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 More sharing options...
gorllzz Posted May 18, 2017 Share Posted May 18, 2017 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 More sharing options...
KoalaBear Posted May 19, 2017 Author Share Posted May 19, 2017 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 More sharing options...
Martin Fabre Posted May 19, 2017 Share Posted May 19, 2017 (edited) 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']; Edited May 19, 2017 by Martin Fabre (see edit history) Link to comment Share on other sites More sharing options...
KoalaBear Posted May 19, 2017 Author Share Posted May 19, 2017 (edited) 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 May 19, 2017 by KoalaBear (see edit history) Link to comment Share on other sites More sharing options...
Martin Fabre Posted May 19, 2017 Share Posted May 19, 2017 (edited) 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 May 19, 2017 by Martin Fabre (see edit history) Link to comment Share on other sites More sharing options...
KoalaBear Posted May 19, 2017 Author Share Posted May 19, 2017 Okay, thank you. I will try StackOverflow. With JS I am able to get the client side URL, but unfortunately I can't use it for my needs. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now