<?php
$path = __DIR__ . '/templates/';
$template = <<<ND
{% extends "base.html.twig" %}
{% block body %}
{{ block("part") }}
<p><strong>regular content</strong></p>
{{ block("part") }}
{% endblock %}
{% block part %}
repeating content
{% endblock %}
ND;
$name = 'string.html.twig';
$loaders = [
new Twig\Loader\ArrayLoader([$name => $template]),
new Twig\Loader\FilesystemLoader($path),
];
$loader = new Twig\Loader\ChainLoader($loaders);
$twig = new Twig\Environment($loader);
echo $twig->render($name);
regular content