Jump to content

[SOLVED] Cutting through the loop


Recommended Posts

Hello,

I am developing a website for a client, and I have been asked to display the features using two columns instead of the usual one. There will be three columns on the product page One column contains the picture of the product and the two others are the features. The latter are features, but the first columns contains general characteristics (reference name, colour, adhesive type,...) of the item while the other columns will be about dimensions (margin, padding, pitch, height,...).

I see in "product-details.tpl" that the items are looped from "$product=grouped_features" array, and as my technical references are containing 16 datafields, I'd like to interrupt the loop at the 8th feature on the first column, and resume the loop the next column.

I know that in some templating languages (Jinja2, Twig, Handlebars), it is possible to do something like that, but I cannot manage to find this with Smarty. Would I have to change something in the deep code?

More than words, an example with pseudocode;

// Column N°1
FOREACH $product.grouped_features START=1(i) STOP=8(i)
    $feature.name(i)
    $feature.value(i)
ENDFOREACH

// Column N°2
FOREACH $product.grouped_features START=9(i) STOP=16(i)
    $feature.name(i)
    $feature.value(i)
ENDFOREACH

(i) being the iteration.

I tried this solution, but it only shows me one iteration. To test, I only have 6 features, I set $smarty.foreach.featureCount.iteration == 4 but it only shows me the 4th value :I have been looking about this for some time now and I run out of ideas. Is that even possible? I am running PrestaShop 1.7.3.

    {foreach from=$product.grouped_features item=feature name=featureCount}
        {if $smarty.foreach.featureCount.iteration == 4}
            <dt class="name">{$feature.name}</dt>
            <dd class="value">{$feature.value|escape:'htmlall'|nl2br nofilter}</dd>
            {break}
         {/if}
    {/foreach}

 

Thank you.

Edited by nsbey
Marking as solved (see edit history)
Link to comment
Share on other sites

The answer has been found. The problem is now solved thanks to this user on StackOverflow : 

{foreach from=$product.grouped_features item=feature name=featureCount}
    <dt class="name">{$feature.name}</dt>
    <dd class="value">{$feature.value|escape:'htmlall'|nl2br nofilter}</dd>
    {if $feature@iteration == 3}
        {break}
    {/if}
{/foreach}

 

 

Link to comment
Share on other sites

  • 10 months later...

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