views:

216

answers:

4

How can i generate a select list with the given year till this year? i did this

{assign var=thisyear value=$smarty.now|date_format:"%Y"}
{if !$firstyear}
 {assign var=firstyear value="2003"}
{/if}

{if !$loop}{assign var=loop value=$thisyear}{/if}
<select name='{$id|default:year}' id={$id|default:year} style='width:70px;'>

 {section name=yearValue max=$year start=$firstyear loop=$thisyear step=-1}
  <option{if $year==$smarty.section.yearValue.index} selected="selected"{/if}>{$smarty.section.yearValue.index}</option>
 {/section}

</select>

unfotunatly this produces 0 till 2003 but i want that it generates 2003 till 2010 how can i do that?

+1  A: 
{section name=years start=2003 loop=2011 step=1}
    {$smarty.section.years.index}
{/section}
karim79
But each year i have to make changes
streetparade
Assign the `start` and `loop` values from PHP, rather than incorporating complex template logic to do the same.
karim79
+1  A: 

Have a look at html_select_date

Htbaa
Thanks for the information
streetparade
You're welcome :-)
Htbaa
+1  A: 

{assign var=firstyear value="2003"} {assign var=thisyear value=$smarty.now|date_format:"%Y"}

{section name=yearValue start=$thisyear loop=$firstyear step=-1} {$smarty.section.yearValue.index} {/section}

Jan Menšík
A: 
{assign var=thisyear value=$smarty.now|date_format:"%Y"}
    {assign var=endYear value=$thisyear+6}
    <select>
        {section name=yearValue start=$thisyear loop=$endYear step=1}<option>{$smarty.section.yearValue.index}</option>
        {/section}
    </select>
phi