2

I'm passing a DateTime object from php to twig, and when calling it on my twig:

{% verbatim %} {{ user.updatedAt }} {% endverbatim %}

I'm getting this output on my page:

{"date":"2017-02-08 18:53:22.000000","timezone_type":3,"timezone":"Europe/Lisbon"}

When I try to apply the filter date("H:i") on this variable, it's not applied and I get this on the page:

{{ user.updatedAt|date("H:i") }}

In this case, I also have the following angularjs error in the console, which I think is related:

Error: [$parse:syntax] Syntax Error: Token '(' is an unexpected token at column 24 of the expression [ user.updatedAt|date("H:i") ] starting at [("H:i") ].

Can anyone explain to me what's going on? How can I fix this?

Thanks in advance. Cheers

  • Hi, without considering the fact the date you are passing is not a javascript date you call the filter in the wrong way. Take a look here https://docs.angularjs.org/api/ng/filter/date – rick Feb 16 '17 at 12:22
  • Hi rick, I'm trying to call the twig date filter, not the angularjs one. Is there a conflict with these filters? How should I do it? Thanks – andregoncalves Feb 16 '17 at 13:19
  • 1
    ok sorry, it seams a pretty common problem, look at this http://stackoverflow.com/questions/13671701/angularjs-twig-conflict-with-double-curly-braces – rick Feb 16 '17 at 13:28

1 Answers1

1

If you want Twig to parse your line and process the date filter, you have to remove the "{% verbatim %}" tags. They are used to explicitly tell Twig that the content of the block is NOT to be parsed.

Your current code is indeed outputting data that is parsed by Angular since the double curly braces are not parsed by Twig, hence your angular parsing exception.

NaeiKinDus
  • 730
  • 20
  • 30
  • Thanks a lot for this. I honestly thought that that variable was being parsed by twig, but it was in fact parsed by angular. The angular date filter is different from the twig one, hence the error. – andregoncalves Feb 17 '17 at 15:34