我正在使用Smarty的網站上工作。我在網上搜索瞭解Smarty是否可以使用switch
。但我無法找到任何有用的鏈接。smarty有沒有Switch case?
是否可以在Smarty中使用Switch case?如果是的話如何?
我正在使用Smarty的網站上工作。我在網上搜索瞭解Smarty是否可以使用switch
。但我無法找到任何有用的鏈接。smarty有沒有Switch case?
是否可以在Smarty中使用Switch case?如果是的話如何?
你可以在這裏找到的文檔: http://www.smarty.net/documentation
不,這不是可能的(無插件)。但你可以在PHP中使用它並分配你的結果。或者在smarty中,您可以用不同的方式使用if條件。
是一個額外的插件: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}
你也可以用一個簡單的if/ELSIF語句,如果你不喜歡,也可以安裝插件:
{if $case1_as_condition}
Case 1
{elseif $case2_as_condition}
Case 2, etc
{else}
Default
{/if}
http://www.smarty.net/docsv2/en/language.function.if
最好的祝願
Andreas
這絕對是可能的,如果你安裝這個插件:http://pynej.blogspot.co.uk/2010/02/switch-statment-for-smarty-3.html –
@JohnMagnolia請添加您的評論作爲答案 –