11/23/2010 - Updated to version 3.5
Updated to work with Smarty 3.0 release. (Tested on 3.0.5).
I removed the code from this posting, it is now available on github here: https://github.com/pynej/Smarty-Switch-Statement/archives/Smarty-3.0
10/28/2010 - Updated to version 3.3
I have added this project to GitHub at http://github.com/pynej/Smarty-Switch-Statement.
02/25/2010 - Updated to version 3.3
Please note that this update is required for version 3.0b6 or grater. The change is simple renaming the execute methods to compile but it not backwards compatible. The Smarty3.0b5 and below version is still available here.
02/09/2010 - Updated to version 3.2
Fixed a bug when chaining case statements without a break.
02/09/2010 - Updated to version 3.1
Updated the plug-in to once again support the shorthand format, {switch $myvar}. To enable this feature you must add the following line to you code somewhere before the template is executed.
$smarty->loadPlugin('smarty_compiler_switch');
If you do not add said line the long hand form will still work correctly.sample.php
/**
* Sample usage:
* <code>
* {foreach item=$debugItem from=$debugData}
* // Switch on $debugItem.type
* {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}
* {/foreach}
* </code>
*
* Note in the above example that the break statements work exactly as expected. Also the switch and default
* tags can take the break attribute. If set they will break automatically before the next case is printed.
*
* Both blocks produce the same switch logic:
* <code>
* {case 1 break}
* Code 1
* {case 2}
* Code 2
* {default break}
* Code 3
* </code>
*
* <code>
* {case 1}
* Code 1
* {break}
* {case 2}
* Code 2
* {default}
* Code 3
* {break}
* </code>
*
* Finally, there is an alternate long hand style for the switch statements that you may need to use in some cases.
*
* <code>
* {switch var=$type}
* {case value="box" break=true}
* {case value="line"}
* {break}
* {default}
* {/switch}
* </code>
*/