Summary
In this chapter, we’ve seen how to define new custom functions and filters for Twig, and how to use them in our template.
You also learned about all the functions and filters provided by Drupal core and by some famous contrib modules.
The most important takeaway of this chapter is that you must put the business logic of your Drupal website as far as possible from the theme layer. This is the only way to build a maintainable and future-proof system, where you can switch the frontend theme without affecting the site features and functionality at all. A Drupal theme must only be responsible for taking some data structures (that is, render arrays) and turning them into HTML.
In the next chapter, Chapter 13, Making a Theme Configurable, we’ll talk about how to build a theme that can be adapted to be used on multiple websites, with some little (or big) differences.