How to use sprintf in Twig to format a number?

I need to format a number like this:

sprintf("%05d",$lineNumber) 

But I'm inside the Symfony2 Twig template. So what can I do?

+4
source share
2 answers

Twig provides a lot of filters , see format and number_format .

+6
source

If i was 4 before, after adding this to the Twig pattern:

"%02d"|format(i)

... he will be 04.

+11
source

All Articles