2011-11-11 120 views
15

我正在使用Smarty的網站上工作。我在網上搜索瞭解Smarty是否可以使用switch。但我無法找到任何有用的鏈接。smarty有沒有Switch case?

是否可以在Smarty中使用Switch case?如果是的話如何?

+2

這絕對是可能的,如果你安裝這個插件:http://pynej.blogspot.co.uk/2010/02/switch-statment-for-smarty-3.html –

+2

@JohnMagnolia請添加您的評論作爲答案 –

回答

7

你可以在這裏找到的文檔: http://www.smarty.net/documentation

不,這不是可能的(無插件)。但你可以在PHP中使用它並分配你的結果。或者在smarty中,您可以用不同的方式使用if條件。

4

是一個額外的插件:http://pynej.blogspot.co.uk/2010/02/switch-statment-for-smarty-3.html

{switch $debugItem.type} 
    {case 1} 
    {case "invalid_field"} 
     // Case checks for string and numbers. 
    {/case} 
    {case $postError} 
    {case $getError|cat:"_ajax"|lower} 
     // Case checks can also use variables and modifiers. 
     {break} 
    {default} 
     // Default case is supported. 
{/switch}