sandra nanou Posted March 10, 2022 Share Posted March 10, 2022 Hello, I'm trying to display my product features separatly. Some will be before the product description, some after and they will all have different design. I managed to separate them using their ID. Now I need to add a specific class to each feature's value. I tried to add a foreach but it's not working as intended. This it what I managed to do so far : <div class="acc"> {foreach from=$product.grouped_features item=feature} {if $feature.id_feature == 13 } <div class="acc__card info-{$feature.id_feature}"> <div class="acc__titleOpen">{$feature.name}</div> <div class="acc__panelOpen"> {foreach $product.features as $feature key=k} {if $k<=3} <span class="value id-{$feature.value}"> {$feature.value|escape:'htmlall'|nl2br nofilter}</span> {/if} {/foreach} </div> </div> {/if} {if $feature.id_feature == 14} <div class="acc__card info-{$feature.id_feature}"> <div class="acc__title">{$feature.name} </div> <div class="acc__panel"> <li class="value id-{$feature.value}"> {$feature.value|escape:'htmlall'|nl2br nofilter}</li> </div> </div> {/if} {/foreach} </div> I have an issue with the {foreach $product.features as $feature key=k} {if $k<=3} <span class="value id-{$feature.value}"> {$feature.value|escape:'htmlall'|nl2br nofilter}</span> {/if} {/foreach} As I did not specify the feature ID (I don't know how to do it...), it loops through the first feature of my list. As help would be so appreciated ! Thank you, Sandra Link to comment Share on other sites More sharing options...
Ress Posted March 12, 2022 Share Posted March 12, 2022 Why are you going through all the features here again? {foreach $product.features as $feature key=k} {if $k<=3} <span class="value id-{$feature.value}"> {$feature.value|escape:'htmlall'|nl2br nofilter}</span> {/if} {/foreach} Isn't it enough to put directly? <span class="value id-{$feature.value}"> {$feature.value|escape:'htmlall'|nl2br nofilter}</span> Link to comment Share on other sites More sharing options...
sandra nanou Posted March 14, 2022 Author Share Posted March 14, 2022 Hi, Thank you for your help. It doesn't loop through each value, all values are inserted into the same <span> , all separated with <br/> : <span class="value id-Choisi aussi par les industriels Fabrication européenne Fil d’acier épais Garantie 10 ans"> Choisi aussi par les industriels<br> Fabrication européenne<br> Fil d’acier épais <br> Garantie 10 ans </span> I need to separate each value into a different span with a different class or ID. Any idea? Link to comment Share on other sites More sharing options...
ventura Posted March 14, 2022 Share Posted March 14, 2022 <p class="feature_{$feature.id_feature}">{$feature.value}</p> 1 Link to comment Share on other sites More sharing options...
sandra nanou Posted March 14, 2022 Author Share Posted March 14, 2022 Hi, Thank you but it's still the same problem : <p class="feature_13">Choisi aussi par les industriels Fabrication européenne Fil d’acier épais de 5mm Garantie 10 ans</p> I need to loop through the different features'values. Link to comment Share on other sites More sharing options...
Ress Posted March 14, 2022 Share Posted March 14, 2022 (edited) Do you have a module that allows you to set multiple values to a feature? L.E. Try this code: Fill in the feature ids, separated by commas, for the 2 sections in which you want to split the features: {assign var=allow_features value=[10,11,12,13]} {assign var=allow_features2 value=[14,15,16]} First section: {assign var=allow_features value=[10,11,12,13]} {foreach from=$product.grouped_features item=feature} {if $feature.id_feature|in_array:$allow_features} <div class="acc__card info-{$feature.id_feature}"> <div class="acc__titleOpen">{$feature.name}</div> <div class="acc__panelOpen"> <span class="value id-{$feature.id_feature}">{$feature.value|escape:'htmlall'|nl2br nofilter}</span> </div> </div> {/if} {/foreach} Second section: {assign var=allow_features2 value=[14,15,16]} {foreach from=$product.grouped_features item=feature} {if $feature.id_feature|in_array:$allow_features2} <div class="acc__card info-{$feature.id_feature}"> <div class="acc__title">{$feature.name} </div> <div class="acc__panel"> <li class="value id-{$feature.id_feature}"> {$feature.value|escape:'htmlall'|nl2br nofilter}</li> </div> </div> {/if} {/foreach} Edited March 14, 2022 by Ress (see edit history) 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