开发者

How to generate year in Smarty?

开发者 https://www.devze.com 2022-12-20 02:36 出处:网络
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\"}

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|def开发者_JS百科ault: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?


Have a look at html_select_date


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


{section name=years start=2003 loop=2011 step=1}
    {$smarty.section.years.index}
{/section}


{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}


{html_select_date start_year="+0" end_year="+0" field_order="DMY" day_value_format="%02d"}

if you want to this year only set in to start year if you give value in minus like "-1" than it show previous year also.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号