Please help me understand the right way to use template inheritance in twig.
I have a template base.html.twig that all my other templates extend. This contains the html, head, body, etc. tags and a few blocks.
I would like to move the < head > section from the base.html.twig template into its own file head.html.twig. If I use the include directive then the title block in that section no longer gets overridden properly by the extending templates.
I determined that I could work around this by setting the title as a variable in the extending template and passing it in my include statement. But now I have pages that need extra bits of javascript loaded in the < head > section, so I have to add variables to indicate which of those to load...
Obviously this is a horrible kludge. What is the right way to do this?
EDIT: At the suggestion of @goto I tried replacing include with embed. Now my code looks like:
{# base.html.twig #}
<!DOCTYPE html>
<html>
{% embed 'AppBundle::head.html.twig' %}
{% block title %}My Company Name{% endblock %}
{% endembed %}
<body>
{% block content %}{% endblock %}
</body>
</html>
{# head.html.twig #}
<head>
<title>{% block title %}{% endblock %}</title>
<!-- load other css, js, etc -->
</head>
{# page.html.twig #}
{% extends 'AppBundle::base.html.twig' %}
{% block title %}{{ page.title }} - My Company Name{% endblock %}
{% block content %}
<h1>{{ page.title }}</h1>
{{ page.content|raw }}
{% endblock %}
But this doesnt work, the title is always "My Company Name".