There are several approaches for accomplish this, I suggest you this approach:
Create a class for your widget:
class MyWidget extends Phalcon\DI\Injectable
{
public function __construct()
{
//...
}
public function execute()
{
//...
}
public function getContent()
{
//...
}
}
Create a widget manager:
class MyWidgetsManager
{
public static function get($widgetClass, $parameters=null)
{
return new $widgetClass($parameters);
}
}
Add a function in volt:
$compiler = $volt->getCompiler();
$compiler->addFunction('render_widget', function($resolvedArgs) {
return 'MyWidgetsManager::get(' . $resolvedArgs . ')->getContent()';
});
Usage:
{{ render_widget('MyWidget', [$param1, $param2]) }}