Search code examples
phpsmartyprestashopprestashop-1.6

How to display a feature value in Prestashop?


I work with Prestashop 1.6.1.7 and I'd like display a feature value of a product within the product list (where you see a list of products) below its name.

We sell garments and in the BO I created a custom feature value (the material of garments, like Cashmere for example) and I'd like to display this value below its name on the product list.

I had added this following code to display the feature value on the product.tpl and it works only there.. I think this variable it's not a "global, public" variable (I just play with PHP, I'm not an expert)

{foreach from=$features item=feature}
<tr class="{cycle values="odd,even"}">
{if isset($feature.value)}
<td>{$feature.name|escape:'html':'UTF-8'}</td>
<td>{$feature.value|escape:'html':'UTF-8'}</td>
{/if}
</tr>
{/foreach}

Solution

  • Have you tried using $product.features instead of $features in your product-list.tpl file ?

    Something like this :

    {foreach from=$product.features item=feature}
    <tr class="{cycle values="odd,even"}">
    {if isset($feature.value)}
    <td>{$feature.name|escape:'html':'UTF-8'}</td>
    <td>{$feature.value|escape:'html':'UTF-8'}</td>
    {/if}
    </tr>
    {/foreach}