将变量注入php包括

I've seen a number of questions here about using variables from an include that look like this:

test.inc.php:

<?php
$variable = "value";
?>

file.php:

<?php
$variable = "something";
include "test.inc.php";
echo $variable; // Should be "value"

Now I'm trying to do it in reverse, and am unsuccessful. This is what it looks like:

template.html.php:

<html><body>Here is the value from the inherited scope: <?= $variable ?></body></html>

file.php:

<?php
$variable = "it's a'me, a'mario!";
include "template.html.php";

I'd expect the output to be:

<html><body>Here is the value from the inherited scope: it's a'me, a'mario!</body></html>

But instead, it is:

<html><body>Here is the value from the inherited scope: </body></html>

Is there any sane way to inject the $variable into the include file? I'm writing a pseudo-templating engine that is based on code previously written by another person, and I am forced to go down this route.

I've thought about using eval, but I need to capture all of the output, and I'm not sure I can do that using eval based on how the included file actually looks.

So how would I go about injecting variables into an include file?