Re: [SMARTY] html_options and smarty counter problem
| From: | messju mohr | Date: | Sat, 19 Apr 2003 10:54:24 +0000 |
| Subject: | Re: [SMARTY] html_options and smarty counter problem | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-9335@lists.php.net to get a copy of this message | ||
On Fri, Apr 18, 2003 at 05:58:18PM -0000, tracy wrote:
> Hello Everyone,
>
> I'm trying to do the following:
>
> {* initialize the count *}
> {counter start=0 skip=1 print=false}
>
> <td class=myFont>
> <SELECT name="proj_{counter}">
> {html_options values=$proj_vals selected="proj_{counter}"
> output=$proj_out}
> </SELECT>
> </td>
>
> Of course the "selected=.." section inside html_options gives me an error.
> Does anyone know how I can specify proj_{counter} variable to the selected
> value??
this is only possible with a temporary variable in between.
but there is another problem:
with 'selected="proj_{counter}"' i assume you want to have the *value*
of the variable named "proj_1" (for example) selected and not the
literal value "proj_1". this is not easy, if even feasible.
instead of variable-variable-names like proj_0, proj_1 etc. , you should
consider using an array $proj with keys 0, 1 etc.
then it is sth like this:
{counter print=false assign=proj_num}
<SELECT name="proj[{$proj_num}]">
{html_options values=$proj_vals selected=$proj.$proj_num output=$proj_out}
</SELECT>
you can also do sth. like (a matter of taste, IMHO):
{html_options name="proj[
$proj_num]" values=$proj_vals
selected=$proj.$proj_num output=$proj_out}
then html_options will genereate the "<select>" for you
as a side-note: the backticks (`) where introduced in Smarty-2.5.0, so syntax
for the above differs, if you use Smarty-2.4.2 .
greetings
messju
> Thanks so much,
> Tracy
>
>
>
> --
> Smarty General Mailing List (http://smarty.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php