Skip to content

[Mercure] Update mercure.rst #20771

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 18, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion mercure.rst
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,11 @@ URL in a dedicated HTML element:
{{ mercure('https://example.com/books/1')|json_encode(constant('JSON_UNESCAPED_SLASHES') b-or constant('JSON_HEX_TAG'))|raw }}
</script>

<!-- with Stimulus -->
<div {{ stimulus_controller('my-controller', {
mercureUrl: mercure('https://example.com/books/1'),
}) }}>

Then retrieve it from your JS file:

.. code-block:: javascript
Expand All @@ -290,6 +295,9 @@ Then retrieve it from your JS file:
const eventSource = new EventSource(url);
// ...

// with Stimulus
this.eventSource = new EventSource(this.mercureUrlValue);

Mercure also allows subscribing to several topics,
and to use URI Templates or the special value ``*`` (matched by all topics)
as patterns:
Expand Down Expand Up @@ -407,7 +415,7 @@ of the ``Update`` constructor to ``true``::
$update = new Update(
'https://example.com/books/1',
json_encode(['status' => 'OutOfStock']),
true // private
private: true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reverted this change while merging. Unfortunately, using named arguments in PHP code samples is forbidden in Symfony Docs. The reason is that the name of the arguments can change, so the examples wouldn't be backwards compatible.

);

// Publisher's JWT must contain this topic, a URI template it matches or * in mercure.publish or you'll get a 401
Expand Down Expand Up @@ -704,6 +712,8 @@ enable it::
:alt: The Mercure panel of the Symfony Profiler, showing information like time, memory, topics and data of each message sent by Mercure.
:class: with-browser

The Mercure hub itself provides a debug tool that can be enabled and available on `/.well-known/mercure/ui/`

Async dispatching
-----------------

Expand Down