-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Spiral Twig Integration #40
Conversation
public function twigRenderer(TwigRenderer $twigRenderer): string | ||
{ | ||
return $twigRenderer->render( | ||
'base.twig', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spiral uses a custom Loader, so not able to use base.html.twig
only base.twig
which .html part is used by Twig autoescape detection. Need to be checked what happens now and why this is the case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Twig\Error\SyntaxError] An exception has been thrown during the compilation of a template ("Unable to load view
default:base.html
, file does not exist.") in "default:base.html". in /tmp/schranz-templating/examples/usages/spiral/vendor/twig/twig/src/Environment.php:521
// Use a hack to get Twig from the ViewManager as it is not available as an service yet | ||
$viewManager = $container->get(ViewManager::class); | ||
|
||
$engines = $viewManager->getEngines(); | ||
|
||
$twigEngine = null; | ||
foreach ($engines as $engine) { | ||
if ($engine instanceof TwigEngine) { | ||
$twigEngine = $engine; | ||
break; | ||
} | ||
} | ||
|
||
if (null === $twigEngine) { | ||
throw new \LogicException( | ||
\sprintf('Expected "%s" to be registered in the view manager.', TwigEngine::class) | ||
); | ||
} | ||
|
||
return $twigEngine->getEnvironment(new ViewContext()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a very hacky implementation getting Twig as a service view ViewManager and via a Fake ViewContext over twigEngine service.
Add Twig Renderer integration into the Spiral Framework.
Sadly there are 2 issues currently: