0

How would I extend the $insert so that I can pass multiple parameters into the function e.g {"Sample text %s this more %s."|inject:$foo:$foo2}.

At the moment it only works with 1 param.

/**
 * Smarty inject modifier plugin
 *
 * Type:     modifier<br>
 * Name:     inject<br>
 * Purpose:  sprintf with a IF empty wrapper
 *
 */
function smarty_modifier_inject($string, $insert)
{
    if(!empty($insert))
        return sprintf($string, $insert);
}
John Magnolia
  • 16,769
  • 36
  • 159
  • 270

1 Answers1

1

you have to modify inject function to take arbitrary number of arguments, like this:

function inject(){
    $args = func_get_args();
    if(count($args) > 1){
        return call_user_func_array('sprintf', $args);
    }
}
dev-null-dweller
  • 29,274
  • 3
  • 65
  • 85