Reputation: 31
I am trying to manipulate a date in my index.html.twig with something like:
{{ myDate | date_modify("+3 day") | date('Y-m-d') }}
and get the error:
The filter "date_modify" does not exist in XXX:YYY:index.html.twig at line 723
I am using Symfony 2.0.16, and the Date used is working so far.
What could be the reason for the filter not being present in the TWIG Library?
(Twig_Error_Syntax: The filter "date_modify" does not exist in "XXX:YYY:index.html.twig" at line 723 (uncaught exception) at /.../.../.../.../.../.../vendor/twig/lib/Twig/Node/Expression/Filter.php line 29)
Upvotes: 0
Views: 1681
Reputation: 3218
Create your twig extension. In your bundle, create Twig/Extension/XXXExtension.php
<?php
namespace XXX\YourBundle\Twig\Extension;
use Symfony\Component\DependencyInjection\ContainerInterface;
class XXXExtension extends \Twig_Extension
{
private $container;
public function __construct(ContainerInterface $container)
{
$this->container = $container;
}
public function getFilters()
{
return array('date_modify' => new \Twig_Filter_Method($this, 'dateModify', array('is_safe' => array('html'))));
}
public function dateModify($rangeDate)
{
// your code
}
}
?>
Upvotes: 0
Reputation: 1487
New in version 1.9.0: The date_modify filter has been added in Twig 1.9.0.
Probably you have an old version
Upvotes: 0