(int) return 0 in addFilter

Hello!

I'm trying to write a custom filter.

$volt
->getCompiler()
->addFilter(
'num2str', 
function($resolvedArgs, $exprArgs){
$number = (int) $resolvedArgs;
return '"' . $number . '"';
 }
);

call filter:

{{contract.repaymentPeriod|num2str}}

$resolvedArgs is in string with the value '18'. but my filter returns 0.

tell me how to convert the left argument to a number?

$resolvedArgs is an array, try:


function($resolvedArgs, $exprArgs){
$number = (int) $resolvedArgs[0];
return '"' . $number . '"';
 }


3.1k

$resolvedArgs is an array, try:


function($resolvedArgs, $exprArgs){
$number = (int) $resolvedArgs[0];
return '"' . $number . '"';
}

filters $resolveArgs is a string. I solved this problem by writing a separate class for the filter.