2011-03-29 4 views
0

html_options를 사용하여 html 옵션을 생성 할 때 string_format을 사용하여 출력 형식을 지정하고 싶습니다. 첫 번째 옵션에 대한 예상대로Smarty의 출력 필터 html_options

<select> 
{$options=range(1,12)} 
{html_options values=$options output=$options|string_format:'%02d'} 
{/select} 

이 01를 제공하지만, 나머지 빈 라벨 : 예를 들어

, 나는 앞에 0 옵션을 얻기 위해 노력하고있어. 이것은 this page에있는 예제 (해당 페이지에서 'truncate'검색)를 기반으로 작동해야하므로 잘못하고 있는지 확실하지 않습니다.

답변

2

어떻게 든 멋진 방법 string_format은 배열에서 작동하지 않습니다.

{section name=foo start=1 loop=13} 
    {$options[$smarty.section.foo.index]=$smarty.section.foo.index|string_format:'%02d'} 
{/section} 

을 그리고 simly options 대신 valuesoutput로 사용 :

<select> 
    {html_options options=$options} 
</select> 
당신이 생각 할 수있는 일은 사전에 연관 배열을 만드는 것입니다