Why not use translation component ? But for your question you can use function or filter:
$di->set('view', function () use ($di) {
$view = new \Phalcon\Mvc\View\Simple();
$volt = new \Phalcon\Mvc\View\Engine\Volt($view, $di);
$compiler=$volt->getCompiler();
$compiler->addFilter('attribute', function ($resolvedArgs, $exprArgs)
{
return vsprintf('%s->{%s}', explode(', ', $resolvedArgs));
});
$view->registerEngines([
'volt' => $volt
]);
return $view;
});
And then in view : {{ object|attribute(xyz) }}
$di->set('view', function () use ($di) {
$view = new \Phalcon\Mvc\View\Simple();
$volt = new \Phalcon\Mvc\View\Engine\Volt($view, $di);
$compiler=$volt->getCompiler();
$compiler->addFunction('attribute', function ($resolvedArgs, $exprArgs)
{
return vsprintf('%s->{%s}', explode(', ', $resolvedArgs));
});
$view->registerEngines([
'volt' => $volt
]);
return $view;
});
And then in view : {{ attribute(object,xyz) }}