Set Parent Template Defined Content to Output in Child Template
You could use include...with, as specified in the Twig Docs here

Example for your case:

{# in Template C #}
{% include 'template-d.twig' with {'foo':'Hello World'} %}


This should give Template D access to foo. Hope that helps!