Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.
Smarty foreach help

 
Post new topic   Reply to topic    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
Yupy
Smarty n00b


Joined: 26 Jul 2012
Posts: 4

PostPosted: Sat Sep 07, 2013 8:36 am    Post subject: Smarty foreach help Reply with quote

Hi, I can't figure out this to use smarty foreach instead of php

Code:
$s = "<select name='type'>\n<option value='0'>(choose one)</option>\n";

            $cats = genrelist();

            foreach ($cats
                     AS
                     $row)
            {
                $s .= "<option value='".$row["id"]."'>".htmlspecialchars($row["name"])."</option>\n";
            }
            $s .= "</select>\n";


How can i do this the right way, i looked at the documentation but in option value show's blank.
Back to top
View user's profile Send private message
IT_Services
Smarty Rookie


Joined: 30 Sep 2013
Posts: 9

PostPosted: Mon Sep 30, 2013 9:41 am    Post subject: Reply with quote

Hi Yupy,

have a look at this:

Php-Code:
Code:
$cats = genrelist();
$template = new Smarty();
$template->assign('catlist', $cats);
$template->display('anytemplate.html');


Template (anytemplate.html):
Code:
<select name="type">
<option value="0">(choose one)</option>
{foreach $catlist as $row}
<option value="{$row.id}">{$row.name|escape}</option>
{/foreach}
</select>


Regards
Florian
Back to top
View user's profile Send private message
Yupy
Smarty n00b


Joined: 26 Jul 2012
Posts: 4

PostPosted: Tue Oct 08, 2013 8:37 pm    Post subject: Reply with quote

Thank you very much

(Multumesc mult)
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP