Jump to content

[SOLVED] Get real path to product images in smarty .tpl-files


redrum

Recommended Posts

How can I get the real image path/folder location for the product images in a smarty .tpl-file?

Product images are stored with the following structure:
Product image id: 1234
Location: www.url.com/img/p/1/2/3/4/1234.jpg

'www.url.com/img/p/1/2/3/4/1234.jpg' is want I want to output in the .tpl-file.

I managed to get the folder structure and file name (ie: 1/2/3/4/1234.jpg) in smarty with the following code:

{$product.id_image|regex_replace:'/.*-/':''|spacify:'/'}/{$product.id_image|regex_replace:'/.*-/':''}.jpg

But I believe regex_replace is a bad practice to use in template files.

Edited by redrum
Title updated with [SOLVED] (see edit history)
Link to comment
Share on other sites

4 hours ago, 4you.software said:

Hi.

{if $product.id_image}
	{$urls.img_prod_url}{Image::getImgFolderStatic($product.id_image)}{$product.id_image}.jpg
{/if}

 

The output for this became
https://www.url.com/img/p/99-1234.jpg
https://www.url.com/img/p/ [product id] - [id image] .jpg )

But I managed to get folder location with this code:

{Image::getImgFolderStatic($product.cover.id_image)}{$product.cover.id_image}.jpg

Thanks for pointing me in the right direction.

  • Like 1
Link to comment
Share on other sites

  • redrum changed the title to [SOLVED] Get real path to product images in smarty .tpl-files

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...