I am working on a website using Smarty. I have searched the web to find out whether or not I can use switch
case with Smarty. But i cannot able to find any useful links for this.
Is it possible to use Switch case in Smarty? if so how?
You can find the documentation here: http://www.smarty.net/documentation
No it's not possible (without a plugin). But you can use it in php and assign your results. Or in smarty you can use the if condition instead in a different way.
You can also just use a simple if / elsif statement, if you don't like or can install the plugin:
{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
Yes with an extra plugin: 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 you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With