Let's get rid of the SPAs! Here's how to get real-time Twig blocks basically. Bisous. 😘
-
Install the dependency
composer req sroze/live-twig
-
Get Mercure Hub running. You can have a look to the Mercure documentation. Simplest is with Docker:
docker run --rm -e CORS_ALLOWED_ORIGINS='http://localhost:8000' -e JWT_KEY='!ChangeMe!' -e DEMO=1 -e ALLOW_ANONYMOUS=1 -e PUBLISH_ALLOWED_ORIGINS='http://localhost,http://localhost:8000' -p 80:80 dunglas/mercure
-
Get your Mercure JWT token. If you are using the default demo
JWT_KEY
, you can get the token from your running hub's homepage.. -
Set environment variables
# .env # ... MERCURE_PUBLISH_URL=http://localhost/.well-known/mercure MERCURE_JWT_TOKEN=[your-token]
-
(While the Flex recipe is not done) Create the following configuration file:
# config/packages/live_twig.yaml live_twig: mercure_publisher: "Symfony\\Component\\Mercure\\PublisherInterface" mercure_public_url: "%env(MERCURE_PUBLISH_URL)%"
{{
render_live(
controller('App\\Controller\\YourController::yourAction', { some: 'parameter' }),
{'tags': ['foo', 'bar-' ~ baz]}
)
}}