简体   繁体   English

如何在Smarty中创造一年?

[英]How to generate year in Smarty?

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? 不幸的是,这产生了0到2003年,但我希望它产生2003年至2010年我该怎么办?

{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"} {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. 如果你想今年只开始一年,如果你给负值的价值比“上一年”显示的“-1”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM