Reference for the Cactus Comments Web Client
The web client is the interface that presents comments to users, and lets log in and post comments. It is run in the browser, and should be embedded into each page that you want a comment section on.
The Matrix protocol requires an account to fetch messages from a room. To allow anonymous access despite this, the web client registers a guest account with the default homeserver when it loads for the first time. Using this guest account, the client can fetch comments without the user having to sign in.
The access token for this guest account is stored in HTML5 localStorage, so it can be re-used across pages.
The default homeserver needs to allow guest registrations, for the client to initialize properly. See the self-hosting section for details on how to set up Synapse for use with Cactus Comments.
The client is styled with plain CSS. The stylesheet is deliberately minimal, in order to maintain a consistent look with the surrounding webpage.
If you want to customize the look and feel of the web client, the best option is to get the default stylesheet and modify it to your needs.
This function should be called somewhere in the embedding webpage, with one argument: an object with the configuration parameters described below:
||Yes||A DOM node, which the comment section will be rendered inside. If you pass a string,
||Yes||The full URL of a Matrix homeserver. This homeserver needs to have an instance of the Cactus appservice running, and have guest registrations enabled.|
||Yes||The server name of the same Matrix homeserver as above. This is usually just the domain part of the homeserver url.|
||Yes||A string identifying the comment section used. If two client instances have the same string here, they will show the same comment section. Cannot contain underscores.|
||No||An integer number of comments to show “per page”. This is both the number of comments loaded initially, and the number of additional comments loaded when “View More” is pressed.|
||No||Whether users can log in using Matrix without leaving the page. If false, the Login button becomes a Matrix.to link. Defaults to true. Introduced in v0.7.0.|
||No||Whether users can post without logging in with their Matrix user. If false, the textarea is disabled when the client is authenticated as a guest. Defaults to true. Introduced in v0.7.0.|
||No||How often to fetch new comments. If zero or negative, updates are never fetched. Defaults to zero. Introduced in v0.8.0.|
For example usage, see the quick start guide.
Configuration using data attributes
You can also initialize a comment section by setting data attributes
on a script tag that imports the web client.
This can be useful if using a Content Security Policy that doesn’t allow
When using data attributes, the
node parameter becomes optional. It defaults to replacing the
script element itself with a comment section.
Here’s a minimal working example using data attributes:
If you want to include the newest release of Cactus Comments on your website,
you should use the
If you want to pin it to a specific version, check out the Gitlab releases page.