$di = new \Phalcon\Di\FactoryDefault();
//Register Volt as a service
$di->set('voltService', function($view, $di) {
$volt = new Volt($view, $di);
$volt->setOptions(array(
"compiledPath" => function($templatePath) {
return '../app/compiled-templates/' .basename($templatePath,'.volt') . '.php';},
"compiledExtension" => ".compiled",
"compiledSeparator" => "_"
));
return $volt;
});
//Register Volt as template engine
$di->set('view', function() {
$view = new SimpleView();
$view->setViewsDir('../app/views/');
$view->registerEngines(array(
".volt" => 'voltService'
));
return $view;
});
//injecting service - xconfig
$di->set('xconfig', function () {
$data = array(
'domain' => 'example.com',
);
return $data;
});
Retreiving this in volt
{{ dump(this.di.get('xconfig')) }} // works
{{ dump('xconfig') }} // doesnt work
How do I access xconfig directly in volt? Is it possible? This is the closest approach I have been able to think of
{% set xconfig = this.di.get('xconfig') %} // set var from di
{{ dump(xconfig) }} // access throughout the volt with the new var