/** * Start a new switch statement. * A variable must be passed to switch on. * Also, the switch can only directly contain {case} and {default} tags. * * @param string $tag_arg * @param Smarty_Compiler $smarty * @return string */ function smarty_compiler_switch($tag_arg, &$smarty) { // Add var= if needed. if (strpos($tag_arg, 'var=') === false) { $tag_arg = 'var=' . $tag_arg; } // Run the smarty code passed in. $_params = $smarty->_parse_attrs($tag_arg); // Make sure we have a var. if (!isset($_params['var'])) { $smarty->_syntax_error("switch: missing 'var' parameter", E_USER_WARNING); return; } // Get the switch data. $switchData =& $smarty->get_template_vars("_switchData"); // Add a new switch data array. if (is_null($switchData)) { $switchData = array(); $smarty->assign_by_ref("_switchData", $switchData); } // Turn auto-break off. array_unshift($switchData, false); // Return the switch. return "switch ({$_params['var']}) {"; }