Skip to content

Commit ec3b3db

Browse files
committed
minor #15994 [Mercure] Update mercure.rst (mdieudonne)
This PR was merged into the 5.3 branch. Discussion ---------- [Mercure] Update mercure.rst fix: add "script" element ending tag fix: complete code-block directive Commits ------- 239c481 Update mercure.rst
2 parents fb9e3ca + 239c481 commit ec3b3db

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

mercure.rst

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ Subscribing to updates in JavaScript from a Twig template is straightforward:
251251
// Will be called every time an update is published by the server
252252
console.log(JSON.parse(event.data));
253253
}
254-
<script>
254+
</script>
255255
256256
The ``mercure()`` Twig function will generate the URL of the Mercure hub
257257
according to the configuration. The URL will include the ``topic`` query
@@ -260,13 +260,15 @@ parameters corresponding to the topics passed as first argument.
260260
If you want to access to this URL from an external JavaScript file, generate the
261261
URL in a dedicated HTML element:
262262

263-
.. code:: twig
263+
.. code-block:: twig
264264
265-
<script type="application/json" id="mercure-url">{{ mercure('https://example.com/books/1')|json_encode(constant('JSON_UNESCAPED_SLASHES') b-or constant('JSON_HEX_TAG'))|raw }}</script>
265+
<script type="application/json" id="mercure-url">
266+
{{ mercure('https://example.com/books/1')|json_encode(constant('JSON_UNESCAPED_SLASHES') b-or constant('JSON_HEX_TAG'))|raw }}
267+
</script>
266268
267269
Then retrieve it from your JS file:
268270

269-
.. code:: javascript
271+
.. code-block:: javascript
270272
271273
const url = JSON.parse(document.getElementById("mercure-url").textContent);
272274
const eventSource = new EventSource(url);

0 commit comments

Comments
 (0)