Hugo Trial
Hugo Trial

Reputation: 396

Smarty/php : how to handle an array

So I've been workin with smarty for only 2 weeks so I basically don't know anything about it. I've got this array :

Array ( 
    [0] => Array 
    (
    [id_personalized_case] => 107 
    [id_cart] => 100 
    [preview_personalized_case] => modules/testmodule/views/case/149467_463684487019256_1997552196_n1369153757_case.1369159695.jpg 
    ) 
    [1] => Array 
    ( 
    [id_personalized_case] => 108 
    [id_cart] => 100 
    [preview_personalized_case] => modules/testmodule/views/case/149467_463684487019256_1997552196_n1369153757_case.1369160030.jpg 
    )
)

What I would like to have is the following way to display information :

<div>
    <img src="modules/testmodule/views/case/149467_463684487019256_1997552196_n1369153757_case.1369159695.jpg">
    <a href="url.php?id_cart=100?id_personalized_case=107">blablabla</a>
</div>
<div>
    <img src="modules/testmodule/views/case/149467_463684487019256_1997552196_n1369153757_case.1369160030.jpg">
    <a href="url.php?id_cart=100?id_personalized_case=108">blablabla</a>
</div>

But I can't find a way to do it in smarty. I've assigned to the correct template the array in the following way :

    $this->context->smarty->assign(array(
        'personalizedDatas' => $personalizedDatas
    ));

$personalizedDatas is the array resulting from my request to the DB and print_r($personalizedDatas) is the array I've displayed below.

Is there someone able to help me, I'm struggling for this simple matter that's insane :( :(

Thanks a lot for reading :)

Upvotes: 0

Views: 126

Answers (1)

Robert
Robert

Reputation: 20286

 {foreach $personalizedDatas as $row}
 <div>
 <img src="{$row.preview_personalized_case}">blablabla</a>
  <a href="url.php?id_cart={$row.id_cart}?id_personalized_case={$row.id_personalized_case}">blablabla</a>
 </div>
{/foreach}

These are basics of Smarty. You can learn more on this site http://www.smarty.net/docs/en/language.function.foreach.tpl

Moreover, you can simplify your assigment by using

$this->context->smarty->assign('personalizedDatas', $personalizedDatas);

In this case you don't need an array.

Upvotes: 1

Related Questions