Skip to content

Latest commit

 

History

History
48 lines (37 loc) · 1.33 KB

README.md

File metadata and controls

48 lines (37 loc) · 1.33 KB

LiveTwig

Let's get rid of the SPAs! Here's how to get real-time Twig blocks basically. Bisous. 😘

Setup

  1. Install the dependency

    composer req sroze/live-twig
    
  2. 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
    
  3. 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..

  4. Set environment variables

    # .env
    # ...
    
    MERCURE_PUBLISH_URL=http://localhost/.well-known/mercure
    MERCURE_JWT_TOKEN=[your-token]
    
  5. (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)%"

Use it!

{{
    render_live(
        controller('App\\Controller\\YourController::yourAction', { some: 'parameter' }),
        {'tags': ['foo', 'bar-' ~ baz]}
    )
}}