Technical Entry Level

How do you structure Twig templates in a Symfony application? Discuss template inheritance, components, and keeping logic out of templates.

Quick Tip

Show clean architecture: "Base template defines blocks for content, sidebar, and scripts. Pages extend it and override only what they need. Complex display logic goes into a Twig extension or entity method, not inline in the template."

What good answers include

Template inheritance: a base layout (base.html.twig) defines blocks that child templates override. Twig components (Symfony UX) provide reusable UI elements with their own logic class. Keep templates thin: complex logic belongs in Twig extensions (custom filters/functions), entity methods, or controller-prepared variables — not in {% if %} chains in templates. Strong candidates discuss: the block system for layout composition, the include and embed tags for partials, Twig namespaces for organising templates, and the importance of escaping (autoescaping is on by default, use the raw filter deliberately).

What interviewers are looking for

Tests template architecture thinking. Candidates who put business logic in Twig or who do not use template inheritance effectively will create hard-to-maintain views. Those who leverage blocks, components, and extensions keep templates readable.

← All Symfony questions