How about adding function :
$dependencyInjector->set('view', function () use ($dependencyInjector,$config) {
$view = new View();
$view->registerEngines(array(
".volt" => function ($view) use ($dependencyInjector,$config) {
$volt = new Volt($view);
$compiler = $volt->getCompiler();
$compiler->addFunction('html_comment',function($resolvedArgs,$exprArgs) use ($dependencyInjector,$config) {
if ($dependencyInjector->get('request')->getHttpHost() == $config->yourDevHost) {
return "<!-- $resolvedArgs -->";
}
return null;
});
return $volt;
}
));
return $view;
});
And then in view:
{{ html_comment('something') }} ?
Im not sure it will work tho cuz i didnt check it. Also instead of this nasty if much better it will be just on put this to constant.
Also we dont really know why you need it. You just want to remove all comments or maybe let them be on DEV and remove on PROD ?