Adding custom Twig Extension: Sample Gist + a question

I created a gist to show how to add a custom Twig extension to Slim V3:

Maybe others will find this useful.

However, I do have 1 question: what is the getName() method used for? If I change it to something non-sensical my extension still works, so I’m a bit puzzled by this.

Thanks for any insights.

There is a little note about this in the Twig documentation for creating an extension.

To keep your extension class clean and lean, it can inherit from the built-in Twig_Extension class instead of implementing the whole interface. That way, you just need to implement the getName() method as the Twig_Extension provides empty implementations for all other methods.

Thanks for pointing this out, I somehow missed this (I’ve done a ton of very quick documentation reading and lots of coding over the past few days, it’s all a bit of a blur).