0

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 :)

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

3 Comments

Thx I'll try it, well, I kept this syntax just because I've removed everything else, but there's an array because they are other things in smarty assignment. I let you know :)
Thx that's the good one I was trying to use an old smarty syntax, with item and name property in the foreach element. This way is way more simple thanks a lot :) :) :)
New smarty's syntax is easier than old

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.