From 239c481082edc7be3a9f350b4dba01f8aaaa06eb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Micha=C3=ABl=20Dieudonn=C3=A9?=
<32196785+mdieudonne@users.noreply.github.com>
Date: Sat, 23 Oct 2021 23:27:06 +0200
Subject: [PATCH] Update mercure.rst
fix: add "script" element ending tag
fix: complete code-block directive
---
mercure.rst | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/mercure.rst b/mercure.rst
index e9d9f163692..9a0c1e9dfea 100644
--- a/mercure.rst
+++ b/mercure.rst
@@ -251,7 +251,7 @@ Subscribing to updates in JavaScript from a Twig template is straightforward:
// Will be called every time an update is published by the server
console.log(JSON.parse(event.data));
}
-
The ``mercure()`` Twig function will generate the URL of the Mercure hub
according to the configuration. The URL will include the ``topic`` query
@@ -260,13 +260,15 @@ parameters corresponding to the topics passed as first argument.
If you want to access to this URL from an external JavaScript file, generate the
URL in a dedicated HTML element:
-.. code:: twig
+.. code-block:: twig
-
+
Then retrieve it from your JS file:
-.. code:: javascript
+.. code-block:: javascript
const url = JSON.parse(document.getElementById("mercure-url").textContent);
const eventSource = new EventSource(url);