Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a Switch case in smarty?

Tags:

smarty

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?

like image 684
balanv Avatar asked Nov 11 '11 10:11

balanv


3 Answers

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.

like image 137
ggzone Avatar answered Oct 25 '22 03:10

ggzone


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

like image 21
Andreas Avatar answered Oct 25 '22 02:10

Andreas


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}
like image 39
Chris Avatar answered Oct 25 '22 02:10

Chris