Jump to content

Product features value as icon/image (if exist)


Recommended Posts

Hello,

 

i'm would like to have icon/png image as product feature value and for that :

 

in product.tpl, i added the line (that works)

<img src="{img_dir}featureicon/{$feature.value}.png"/>

but there is a problem. And IF there's NO icon for that feature value?? so i need to display the value himself.

 

i  tried:

{assign var="icon" value="{$img_dir}feature-icons/{$feature.value}.png"}
{if file_exists($icon)}
    <td><img src="{$img_dir}feature-icons/{$feature.value}.png"/></td>
{else}
    <td>{$feature.value|escape:'html':'UTF-8'}</td>
{/if}

but without a chance, i got always the value even for those that have an icon/image.

 

 

any idea? Thanks.....

 

 

Link to comment
Share on other sites

  • 4 years later...

This code works in 1.6 - file: product.tpl:

replace this

{foreach from=$features item=feature}
					
	{if isset($feature.value)}
		<li><b>{$feature.name|escape:'html':'UTF-8'}:</b> {$feature.value|escape:'html':'UTF-8'}</li>
	{/if}
				
{/foreach}

With:

{foreach from=$features item=feature}			
	{if isset($feature.value)}
		{assign var="iconFeat" value="img/icons/{$feature.value}.jpg"}
			{if file_exists($iconFeat)}
    					<td><img src="http://yourwebsite.com/img/icons/{$feature.value}.jpg"/></td>
				{else}
    					<li><b>{$feature.name|escape:'html':'UTF-8'}:</b> {$feature.value|escape:'html':'UTF-8'}</li>
			{/if}	
	{/if}			
{/foreach}

 

Create a folder called "icons" inside your "img" folder within the root directory (outside the themes folder). Place all your icon images inside the new "icon" folder and make sure the image filename matches exactly the same as the product features value setup in the backend (do not include image extension ".jpg" within the feature value). Also, make sure none of your images or product feature values are the same for other features. 

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