Test your Twig Extensions knowledge with a free interactive quiz — 20 questions with answers and explanations. No signup needed to play.
Question 1/12Score 0
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?
In this round
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?
How does registering a custom Twig extension in a Symfony application typically happen (in terms of dependency injection/service registration)?
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 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")?
How do you create a custom Twig filter within an extension, and what does it let a template do?
What is the significance of a Twig filter/function extension being able to accept OPTIONS (like `needs_environment` or `needs_context`) when registered?
Why might overusing custom Twig extensions to add many highly-specific, narrowly-applicable filters/functions eventually become a maintenance concern for a project?
What is the purpose of the `TwigFilter`/`TwigFunction`/`TwigTest` classes themselves (as opposed to just returning plain arrays or callables directly)?
What does it mean that a Twig filter/function can be registered with the `is_safe` option (e.g. `new TwigFilter('markdown', [$this, 'renderMarkdown'], ['is_safe' => ['html']])`)?
What is the purpose of `getGlobals()` in a Twig extension, as distinct from `getFilters()`/`getFunctions()`?
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?
What is a "Twig node visitor" (an advanced extension feature registered via `getNodeVisitors()`), and how does it differ from a simple filter/function?