Including a sub-template in a theme I've read numerous answers to similar questions here but I can't for the life of me work out how to do this seemingly simple thing. I simply want to include a Twig template (theme_name/templates/system/footer.twig.html) from another Twig template in my custom theme (theme_name/templates/system/page.twig.html).

In my page.html.twig I've tried all of the following (obviously with theme_name as the actual theme name):

{% include 'themes/custom/theme_name/templates/system/footer.html.twig' %}
{% include 'footer.html.twig' %}
{% include 'system/footer.html.twig' %}
{% include directory ~ '/system/footer.html.twig' %}
{% include '/' ~ directory ~ '/system/footer.html.twig' %}
{% include "@theme_name/system/footer.html.twig" %}
{% include "/var/www/html/web/themes/custom/theme_name/system/footer.html.twig" %}


Each of these produces the following error, with the template varying on the method I've tried:


  Twig_Error_Loader: Template
  "themes/custom/theme_name/templates/footer.html.twig" is not defined
  (Drupal\Core\Template\Loader\ThemeRegistryLoader: Unable to find
  template "themes/custom/theme_name/templates/footer.html.twig" in the
  Drupal theme registry.) in
  "themes/custom/theme_name/templates/homepage/page--front.html.twig" at
  line 177. in Twig_Loader_Chain->getCacheKey() (line 115 of
  /var/www/html/vendor/twig/twig/lib/Twig/Loader/Chain.php).


I've even tried using hook_theme in my theme_name.theme file to no avail.

&lt;?php

function my_theme_theme() {
  return [
    'footer' =&gt; [
      'variables' =&gt; [],
    ],
  ];
}
No need to set up hook_theme, Just include like this:

{% include '@theme_name/system/footer.html.twig' with content %}


this will include that template in your main template.  The variables will need to be available from the main template.  

The "with" statement sets up the variables being sent to the sub-template.  See http://twig.sensiolabs.org/doc/tags/include.html