You could use the template_from_string
function.
See the documentation here and here.
You need to scroll a bit down in the second link to Twig_Loader_String
. Direct link to this loader
Twig_Loader_String
loads templates from strings. It's a dummy loader as the template reference is the template source code
It seems to be necessary to explicitly say you want to use it as seen in the first link:
$twig = new Twig_Environment(...);
$twig->addExtension(new Twig_Extension_StringLoader());
Also possible directly in your twig template (first link)
{{ include(template_from_string("Hello {{ name }}") }}
{{ include(template_from_string(page_content)) }}