Search code examples
prestashopsmarty

Show each result on a smarty multiple lines


I am trying to display the results of a table on several lines. I have a table with a key => value. Currently my code looks like this, but only displays one value:

{$i = 0}
            {foreach from=$features item=feature}
                <div class="col-xs-12 col-md-12 col-lg-12">
                    <div class="row">
                        {if isset($feature.values) && $feature.id_feature == 199}
                            {*<div class="col-xs-4 col-md-4 col-lg-4">
                                <img src="{$img_dir}icon-{$feature.values|lower|replace:' ':'-'}-black.png">
                            </div>*}
                            <div class="col-xs-8 col-md-8 col-lg-8">
                                <p class="accord_title">{$feature.values[$i]|escape:'html':'UTF-8'}</p>
                            </div>
                            {$feature.values|@print_r}
                        {/if}
                    </div>
                </div>

                {$i = $i+1}
            {/foreach}

I would like this to resemble this in the finality

finality

My table looks like this right now:

    $features   Smarty_Variable Object (3)
->value = Array (4)
  141 => Array (4)
    values => Array (1)
      0 => "Bouteille 75cl"
    name => "Contenance"
    id_feature => "141"
    value => "Bouteille 75cl"
  195 => Array (4)
    values => Array (1)
      0 => "Vin Moelleux"
    name => "Typologie"
    id_feature => "195"
    value => "Vin Moelleux"
  197 => Array (4)
    values => Array (1)
      0 => "Gewurztraminer Sélection de Grains No..."
    name => "Appellation"
    id_feature => "197"
    value => "Gewurztraminer Sélection de Grains No..."
  199 => Array (4)
    values => Array (11)
      0 => "Charcuterie"
      1 => "Desserts"
      2 => "Fruits de mer"
      3 => "Plats en sauce"
      4 => "Plats épicés"
      5 => "Poissons"
      6 => "Viandes blanches"
      7 => "Viandes rouges"
      8 => "Volaille"
      9 => "Apéritifs"
      10 => "Fromages"
    name => "Accords mets-vin"
    id_feature => "199"
    value => "Charcuterie, Desserts, Fruits de mer,..."
->nocache = false
->scope = "file:D:\WAMP\www\vm.fr/themes/..."

Thank you for help.


Solution

  • I found how to do it, here is the solution:

    {$i = 0}
                {foreach from=$features item=feature}
                    {if isset($feature.values) && $feature.id_feature == 199}
                        {foreach from=$feature.values item=val}
                            <div class="col-xs-12 col-md-12 col-lg-12">
                                <div class="row">
                                    <div class="col-xs-4 col-md-4 col-lg-4">
                                        <img src="{$img_dir}icon-{$val|lower|replace:' ':'-'}-black.png">
                                    </div>
                                    <div class="col-xs-8 col-md-8 col-lg-8">
                                        <p class="accord_title">{$val|escape:'html':'UTF-8'}</p>
                                    </div>
                                </div>
                            </div>
                            {$i = $i +1}
                        {/foreach}
                    {/if}
                {/foreach}