0

I am looking help about smarty global variables. How to get friendly URL variable for using it in smarty template of the Prestashop. I have found this {$smarty.server.REQUEST_URI} , but I got only full URL. It looks like: /en/our-products/73-lighted-mirror-tokyo-70-x-32.html

I need to get only 73-lighted-mirror-tokyo-70-x-32 sting.

Help, please.

Antony
  • 85
  • 1
  • 10
  • With JS you ca try to do `var myURL = yourURL.substr(element.$.img.src.lastIndexOf('/') + 1)` – Kasia Jan 30 '17 at 08:33
  • thanks buddy, but i need to get it in Smarty variable. – Antony Jan 30 '17 at 08:55
  • `{assign var="slash_at" value=$var|strpos:"/"}` and then `{$url|substr:$slash _at+1}` , answer from here http://stackoverflow.com/questions/4389978/smarty-getting-substring-of-a-var-with-strpos-as-start-and-strlen-as-end – Kasia Jan 30 '17 at 09:11

2 Answers2

1

You can also use the getUrlRewriteInformations() function from the Product class in PrestaShop.

It can return the information about the URL Rewrites of any product using the following line of code:

$rewrite_info = Product::getUrlRewriteInformations($id_product);
Knowband Plugins
  • 1,297
  • 1
  • 7
  • 6
0

Great, it was help full. I have found the solution for get current product slug on the product page of the Prestashop:

Source URL: /en/our-products/2-backlit-mirror-rectangle-20-x-28.html

{assign var="var" value=$smarty.server.REQUEST_URI}
{assign var="output" value=$var|substr:0:($var|strpos:"."+0)}
{assign var=slug value=$output|substr:($output|strpos:"/"+17)}
{$slug}

Slug: 2-backlit-mirror-rectangle-20-x-28

Antony
  • 85
  • 1
  • 10