Twig 4.0 overhauls the macro system to make it strict and consistent with how functions and filters work. Key changes include: required arguments (unless a default is declared), explicit variadic arguments using `...` notation instead of the implicit `varargs` magic variable, mandatory parentheses when calling macros, and case-sensitive macro names. Previously, macros silently swallowed typos, missing arguments, and extra arguments — all of which now produce clear error messages. Additional improvements include dynamic macro names (available since Twig 3.28) and a `deprecated` tag for macro libraries. A smooth upgrade path exists via Twig 3.29, which triggers deprecation warnings for all patterns that will break in 4.0.
Table of contents
The Problem: Macros Are Too ForgivingRequired ArgumentsExplicit Variadic ArgumentsCalls Look Like CallsClear Errors Instead of Broken OutputA More Capable Macro ToolboxThe Upgrade Path7.4K Impressions