Skip to content

Commit

Permalink
feat: Добавлена поддержка пользовательских расширений для twig-шаблон…
Browse files Browse the repository at this point in the history
…изатора
  • Loading branch information
e.kremnev committed Dec 28, 2022
1 parent 76f94d9 commit d8faf1f
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/PhpDocxTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace PhpDocxTemplate;

use DOMDocument;
use Twig\Extension\ExtensionInterface;
use Twig\Loader\ArrayLoader;
use Twig\Environment;
use PhpDocxTemplate\Twig\Impl\{
Expand Down Expand Up @@ -33,6 +34,8 @@ class PhpDocxTemplate
private $picToReplace;
private $picMap;

private $twigExtensions = [];

/**
* Construct an instance of PhpDocxTemplate
*
Expand Down Expand Up @@ -426,6 +429,16 @@ private function cleanTags(array $matches): string
);
}

/**
* Добавить пользовательское расширение
*
* @param ExtensionInterface $ext
*/
public function addTwigExtensions(ExtensionInterface $ext): void
{
$this->twigExtensions[] = $ext;
}

/**
* Render xml
*
Expand All @@ -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(
Expand Down

0 comments on commit d8faf1f

Please sign in to comment.