diff --git a/src/PhpDocxTemplate.php b/src/PhpDocxTemplate.php index c87bb82..9bbde55 100644 --- a/src/PhpDocxTemplate.php +++ b/src/PhpDocxTemplate.php @@ -3,6 +3,7 @@ namespace PhpDocxTemplate; use DOMDocument; +use Twig\Extension\ExtensionInterface; use Twig\Loader\ArrayLoader; use Twig\Environment; use PhpDocxTemplate\Twig\Impl\{ @@ -33,6 +34,8 @@ class PhpDocxTemplate private $picToReplace; private $picMap; + private $twigExtensions = []; + /** * Construct an instance of PhpDocxTemplate * @@ -426,6 +429,16 @@ private function cleanTags(array $matches): string ); } + /** + * Добавить пользовательское расширение + * + * @param ExtensionInterface $ext + */ + public function addTwigExtensions(ExtensionInterface $ext): void + { + $this->twigExtensions[] = $ext; + } + /** * Render xml * @@ -442,6 +455,12 @@ private function renderXml(string $srcXml, array $context): string 'index' => $srcXml, ])); + /** + * Пользовательские расширения + */ + foreach ($this->twigExtensions as $ext) { + $template->addExtension($ext); + } $ext = new ImageExtension(); $ext->setRenderer(