Category Archives: Twig

Zero-padding (and other things) a string with the Twig template engine

This might sound a bit “duh” when you come to the conclusion but I did have to search for it and couldn’t find an immediate answer. I want to zero-pad a month variable to always be 2 digits long, using the Twig template engine Twig doesn’t actually have a built-in filter for this. {{month|pad(‘0+’,2)}} doesn’t exist. However, Twig does have a filter called format that gives you access to the power of sprintf. You can…

Read More