Test your Twig Extensions knowledge with a free interactive quiz — 20 questions with answers and explanations. No signup needed to play.
Question 1/5Score 0
What is a reasonable strategy for organizing multiple related custom filters/functions within a project -- should they all live in one single giant extension class, or be split into several smaller extension classes?
Questions in this quiz
What is a reasonable strategy for organizing multiple related custom filters/functions within a project -- should they all live in one single giant extension class, or be split into several smaller extension classes?
What is the difference between registering a custom Twig "function" versus a custom "filter" within an extension, in terms of how they're called from a template?
How does registering a custom Twig extension in a Symfony application typically happen (in terms of dependency injection/service registration)?
What happens if two different registered Twig extensions both attempt to register a filter with the SAME name (e.g. both defining a filter called "format")?
What is the relationship between Twig's own bundled/built-in extensions (like the "Core" extension providing `if`/`for`/`upper`/`lower`, etc.) and the concept of a user-defined custom extension?
How do you create a custom Twig filter within an extension, and what does it let a template do?
What is a custom Twig "test" (registered via `getTests()` in an extension), and how is it used in a template, e.g. `{% if product is expensive %}`?
What is the purpose of `getGlobals()` in a Twig extension, as distinct from `getFilters()`/`getFunctions()`?
What is a custom Twig "tag" (registered via a `TokenParser`), and why is it generally considered more complex to implement than a custom filter or function?
What is the purpose of the `TwigFilter`/`TwigFunction`/`TwigTest` classes themselves (as opposed to just returning plain arrays or callables directly)?
What is a reasonable justification for keeping custom Twig extension code (filters/functions) focused purely on PRESENTATION-related transformations, rather than embedding genuine business logic (like a discount calculation) inside an extension?
What is the significance of a Twig filter/function extension being able to accept OPTIONS (like `needs_environment` or `needs_context`) when registered?