spiral / twig-bridge Goto Github PK
View Code? Open in Web Editor NEWSpiral Framework: Twig Adapter
License: MIT License
Spiral Framework: Twig Adapter
License: MIT License
@SerafimArts
I assume there should be an actual php 7.4 and 8.0 versions + CI builds for min/max stability also
Currently I can not create a template like base.js.twig
or base.html.twig
.
It ends up in:
[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
I did try to adopt the TwigLoader
here:
twig-bridge/src/TwigLoader.php
Lines 44 to 48 in 0463fab
By changing this:
- \sprintf('%s:%s', $source->getNamespace(), $source->getName()),
+ \sprintf('%s:%s', $source->getNamespace(), $source->getName() . '.twig'),
This way the twig template is rendered. But still not the correct escaper is used.
For example when creating a test.js.twig
file:
<script>
var test = 'test';
{% set someHtml = '<h1>' ~ title ~ '</h1>' %}
var test = "{{ someHtml }}";
alert(test);
</script>
It is not escaped as expected:
Spiral:
Uses still HTML escaper:
Symfony:
Use the JS escaper as expected:
Twig itself or the Twig Environment
would be nice to have as a service itself. So other libraries and systems build on top of Twig can easily be used inside Spiral without have to get Twig in hacky way or have two seperate instances of twig
Currently in schranz-templating/templating#40 (comment)
I'm using a very hacky solution to get Twig from this package:
$container->bindSingleton('twig', function (Container $container) {
// 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());
});
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.