Implement very basic twig parser
This commit is contained in:
@ -45,8 +45,11 @@ readonly class SnipContentService
|
||||
return $this->rebuildText($contentRepo->find($snip->getActiveVersion()));
|
||||
}
|
||||
|
||||
public function rebuildText(SnipContent $snipContent): string
|
||||
public function rebuildText(?SnipContent $snipContent): string
|
||||
{
|
||||
if ($snipContent === null) {
|
||||
return '';
|
||||
}
|
||||
if ($snipContent->getText()) {
|
||||
return $snipContent->getText();
|
||||
}
|
||||
|
24
src/Service/SnipParser/Twig/TwigParser.php
Normal file
24
src/Service/SnipParser/Twig/TwigParser.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service\SnipParser\Twig;
|
||||
|
||||
use App\Service\SnipParser\AbstractParser;
|
||||
use Twig\Environment;
|
||||
use Twig\Loader\ArrayLoader;
|
||||
|
||||
class TwigParser extends AbstractParser
|
||||
{
|
||||
public static function getName(): string
|
||||
{
|
||||
return 'twig';
|
||||
}
|
||||
|
||||
public function parseView(string $content): string
|
||||
{
|
||||
$arrayLoader = new ArrayLoader([
|
||||
'index' => $content,
|
||||
]);
|
||||
$twig = new Environment($arrayLoader);
|
||||
return $twig->render('index');
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user