2011-12-06 7 views
0

私はこのような多次元配列している:私のTPLでSmartyの多次元配列

$products Smarty_Variable Object (3) 
->value = Array (2) 
    0 => Array (73) 
    id_product => "1" 
    id_supplier => "1" 
    id_manufacturer => "1" 
    id_tax_rules_group => "1" 
    id_category_default => "2" 
    id_color_default => "2" 
    on_sale => "0" 
    online_only => "0" 
    ean13 => "0" 
    upc => null 
    ecotax => "0.000000" 
    quantity => "50" 
    minimal_quantity => "1" 
    price => 189.05 
    wholesale_price => "70.000000" 
    unity => null 
    unit_price_ratio => "0.000000" 
    additional_shipping_cost => "0.00" 
    reference => "" 
    supplier_reference => "" 
    location => null 
    width => "0" 
    height => "0" 
    depth => "0" 
    weight => "0.5" 
    out_of_stock => "2" 
    quantity_discount => "0" 
    customizable => "0" 
    uploadable_files => "0" 
    text_fields => "0" 
    active => "1" 
    available_for_order => "1" 
    condition => "new" 
    show_price => "1" 
    indexed => "1" 
    cache_is_pack => "0" 
    cache_has_attachments => "0" 
    cache_default_attribute => "31" 
    date_add => "2011-12-02 17:35:57" 
    date_upd => "2011-12-02 17:35:57" 
    id_product_attribute => "31" 
    description => "<p><strong><span style="font-size: sm..." 
    description_short => "<p>New design. New features. Now in 8..." 
    available_now => "In stock" 
    available_later => "" 
    link_rewrite => "ipod-nano" 
    meta_description => "" 
    meta_keywords => "" 
    meta_title => "" 
    name => "iPod Nano" 
    id_image => "1-37" 
    legend => "iPod Nano" 
    manufacturer_name => "Apple Computer, Inc" 
    tax_name => "TVA FR 19.6%" 
    rate => "19.600" 
    category_default => "iPods" 
    new => "1" 
    orderprice => "149.0000002400000" 
    attribute => Array (16) 
     25 => Array (2) 
     0 => Array (3) 
      public_group_name => "Color" 
      attribute_name => "Blue" 
      id_product_attribute => "25" 
     1 => Array (3) 
      public_group_name => "Disk space" 
      attribute_name => "16Go" 
      id_product_attribute => "25" 
     26 => Array (2) 
     0 => Array (3) 
      public_group_name => "Color" 
      attribute_name => "Blue" 
      id_product_attribute => "26" 
     1 => Array (3) 
      public_group_name => "Disk space" 
      attribute_name => "8Go" 
      id_product_attribute => "26" 
     27 => Array (2) 
     0 => Array (3) 
      public_group_name => "Disk space" 
      attribute_name => "16Go" 
      id_product_attribute => "27" 
     1 => Array (3) 
      public_group_name => "Color" 
      attribute_name => "Yellow" 
      id_product_attribute => "27" 
     28 => Array (2) 
     0 => Array (3) 
      public_group_name => "Disk space" 
      attribute_name => "8Go" 
      id_product_attribute => "28" 
     1 => Array (3) 
      public_group_name => "Color" 
      attribute_name => "Yellow" 
      id_product_attribute => "28" 
     29 => Array (2) 
     0 => Array (3) 
      public_group_name => "Color" 
      attribute_name => "Metal" 
      id_product_attribute => "29" 
     1 => Array (3) 
      public_group_name => "Disk space" 
      attribute_name => "16Go" 
      id_product_attribute => "29" 
     30 => Array (2) 
     0 => Array (3) 
      public_group_name => "Color" 
      attribute_name => "Metal" 
      id_product_attribute => "30" 
     1 => Array (3) 
      public_group_name => "Disk space" 
      attribute_name => "8Go" 
      id_product_attribute => "30" 
     32 => Array (2) 
     0 => Array (3) 
      public_group_name => "Color" 
      attribute_name => "Black" 
      id_product_attribute => "32" 
     1 => Array (3) 
      public_group_name => "Disk space" 
      attribute_name => "8Go" 
      id_product_attribute => "32" 
     33 => Array (2) 
     0 => Array (3) 
      public_group_name => "Color" 
      attribute_name => "Orange" 
      id_product_attribute => "33" 
     1 => Array (3) 
      public_group_name => "Disk space" 
      attribute_name => "16Go" 
      id_product_attribute => "33" 
     34 => Array (2) 
     0 => Array (3) 
      public_group_name => "Color" 
      attribute_name => "Orange" 
      id_product_attribute => "34" 
     1 => Array (3) 
      public_group_name => "Disk space" 
      attribute_name => "8Go" 
      id_product_attribute => "34" 
     35 => Array (2) 
     0 => Array (3) 
      public_group_name => "Color" 
      attribute_name => "Pink" 
      id_product_attribute => "35" 
     1 => Array (3) 
      public_group_name => "Disk space" 
      attribute_name => "16Go" 
      id_product_attribute => "35" 
     36 => Array (2) 
     0 => Array (3) 
      public_group_name => "Color" 
      attribute_name => "Pink" 
      id_product_attribute => "36" 
     1 => Array (3) 
      public_group_name => "Disk space" 
      attribute_name => "8Go" 
      id_product_attribute => "36" 
     39 => Array (2) 
     0 => Array (3) 
      public_group_name => "Color" 
      attribute_name => "Green" 
      id_product_attribute => "39" 
     1 => Array (3) 
      public_group_name => "Disk space" 
      attribute_name => "16Go" 
      id_product_attribute => "39" 
     40 => Array (2) 
     0 => Array (3) 
      public_group_name => "Color" 
      attribute_name => "Green" 
      id_product_attribute => "40" 
     1 => Array (3) 
      public_group_name => "Disk space" 
      attribute_name => "8Go" 
      id_product_attribute => "40" 
     41 => Array (2) 
     0 => Array (3) 
      public_group_name => "Disk space" 
      attribute_name => "16Go" 
      id_product_attribute => "41" 
     1 => Array (3) 
      public_group_name => "Color" 
      attribute_name => "Purple" 
      id_product_attribute => "41" 
     42 => Array (2) 
     0 => Array (3) 
      public_group_name => "Disk space" 
      attribute_name => "8Go" 
      id_product_attribute => "42" 
     1 => Array (3) 
      public_group_name => "Color" 
      attribute_name => "Purple" 
      id_product_attribute => "42" 
     31 => Array (2) 
     0 => Array (3) 
      public_group_name => "Color" 
      attribute_name => "Black" 
      id_product_attribute => "31" 
     1 => Array (3) 
      public_group_name => "Disk space" 
      attribute_name => "16Go" 
      id_product_attribute => "31" 

私はこれを持っている:

{foreach from=$product.attribute key='id_attribute' item='attribute'} 
<li>{$attribute}</li> 
{/foreach} 

このコードは私の配列を返します。

は、どのように私はすべての値がこのように表示することができます。

  • カラー青、ディスク容量:16Go(配列25)
  • カラー青、ディスク容量:8Go(配列26)
  • ..

複数のforeachを作成する必要がありますか? thx

答えて

1

はい、内部には{foreach}ブロックが必要です。

{foreach from=$product.attribute key='id_attribute' item='attribute'} 

    <li> 

     {foreach from=$attribute key='id_property' item='property'} 
      {$property.public_group_name} 
      {$property.attribute_name} 
     {/foreach} 

    </li> 

{/foreach} 
+0

これはうまく動作します! – prestarocket