Tutorial by Examples

base.twig.html <!DOCTYPE html> <html> <head> <title>{{ title | default('Hello World') }}</title> <link rel="stylesheet" type="text/css" href="theme.css"> {% block css %} {% endblock %} &...
article.twig.html <article> <h1>{{ article.title }}</h1> {% block content %} <p>{{ article.content }}</p> {% endblock %} </article> articles.twig.html {# use default template for article #} {% for article in articles %} {% include &...
parent.html.twig <!DOCTYPE html> <html> <head> <title>{{ title_variable | default('Normal Page') }}</title> </head> <body> <h1>This is the {{ title_variable }} Page</h1> </body> </html> ...
There are various types of inheritance and code reuse in Twig: Include The main goal is code reuse. Consider using header.html.twig & footer.html.twig inside base.html.twig as an example. header.html.twig <nav> <div>Homepage</div> <div>About</div> </...

Page 1 of 1