Hi all, I have a custom function to convert money value. If I add the currency symbol to the return value I receive this error:
ParseError: syntax error, unexpected '$', expecting ',' or ';'
path_to_index.volt.compiled (78)
I've discovered that the error is generated by the final symbol (if I remove it, the function and the template work).
Is it a volt's bug? Is there a way to return a value with the currency symbol?
This is the simple piece of code
$volt = $this->di->get('voltService'); $compiler = $volt->getCompiler(); $compiler->addFunction('currency_conversion', function($resolvedArgs, $exprArgs) { $var = \App\Models\Currency::conversion($exprArgs[0]['expr']['value'],$exprArgs[1]['expr']['value']); return $var; });
UPDATE: It throws a syntax error even if I use "EUR" or "USD" instead of the symbol. The convert function is:
public static function conversion($value,$currency=null){ $di = \Phalcon\DI::getDefault(); if(isset($currency)) { $cur=self::findFirstByCode($currency); $exchange = $value * $cur->getValue(); } elseif( $di->get('session')->get('currency') ) { $currency = $di->get('session')->get('currency'); $cur=self::findFirstByCode($currency); $exchange = $value * $cur->getValue(); } else { $currency='EUR'; $cur=self::findFirstByCode($currency); $exchange = $value * $cur->getValue(); } return (string)( round($exchange,2).' '.$cur->getCode() ); }