|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
Yupy Smarty n00b
Joined: 26 Jul 2012 Posts: 4
|
Posted: Sat Sep 07, 2013 8:36 am Post subject: Smarty foreach help |
|
|
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 |
|
IT_Services Smarty Rookie
Joined: 30 Sep 2013 Posts: 9
|
Posted: Mon Sep 30, 2013 9:41 am Post subject: |
|
|
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 |
|
Yupy Smarty n00b
Joined: 26 Jul 2012 Posts: 4
|
Posted: Tue Oct 08, 2013 8:37 pm Post subject: |
|
|
Thank you very much
(Multumesc mult) |
|
Back to top |
|
|
|
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
|