Hi all,
I've stored a time in my database as a MySQL datetime stamp (YYYY-MM-DD HH:MM:SS). I want to reformat it (change from 24-hour to 12-hour) when displaying in my template.
When I was using raw PHP, I would just call
<?PHP
$formatted = date('Y-m-d g:i:s A',strtotime($timestamp_from_db));
However, when I override Volt's default call to date() and substitute that in, I get this error: "Parse error: syntax error, unexpected ''; ?>' (T_ENCAPSED_AND_WHITESPACE)"
Here is the code in my Bootstrap that sets up Volt:
<?PHP
$View->registerEngines(['.phtml'=> function($View,$DI) use ($Config){
$Volt = new \Phalcon\Mvc\View\Engine\Volt($View,$DI);
$Volt->setOptions([ 'compiledPath' => $Config->app->viewsCompileDir,
'compileAlways' => $Config->app->viewsCompileAlways
]);
$Compiler = $Volt->getCompiler();
$Compiler->addFunction('date',function($args){
return date($args[0],strtotime($args[1]));
});
return $Volt;
}
]);
Here is the code in my Volt template that invokes my overridden date() function, and which generates the error:
{{ date('Y-m-d g:i:s A',Request.date_submitted) }}
Oh, and as you can see I have Volt set to always re-compile the templates.
Thanks!