A component, integrated with FT authentication and Coral Talk, to add a comment stream or comment count to content.
Check out how to include Origami components in your project to get started with o-comments.
Unlike other Origami components o-comments requires additional peer dependencies.
o-comments is dependant on sass from o-overlay and o-forms and requires them to be included by the parent application.
These elements will be initialized automatically on the o.DOMContentReady event meaning you're unable to defer component initialisation.
Use the following markup to enable a comment stream:
<div class="o-comments"
id="{element-id}"
data-o-component="o-comments"
data-o-comments-article-id="{article-id}"
data-o-comments-article-url="{optional-article-url}">
</div>Coral needs a parent element id when initialising the comment stream embed script.
Add the following attribute to the markup to enable a comment count:
<div class="o-comments"
- id="{element-id}"
data-o-component="o-comments"
data-o-comments-article-id="{article-id}"
+ data-o-comments-count="true">
</div>The comment count is rendered when the data-o-comments-count attribute value is true.
If you need the count as a value, use the getCount method which returns an integer.
Comments.getCount('article-id')
.then(count => console.log(count));Add the following attribute to the markup to use Coral staging environment:
For stream:
<div class="o-comments"
id="o-comments-stream"
data-o-component="o-comments"
data-o-comments-article-id="{article-id}"
data-o-comments-article-url="{optional-article-url}"
+ data-o-comments-use-staging-environment="true">
</div>For count:
<div class="o-comments"
data-o-component="o-comments"
data-o-comments-article-id="{article-id}"
data-o-comments-count="true"
+ data-o-comments-use-staging-environment="true">
</div>In rare cases, a user may have already set their display name in a different part of the website. In this instance, add the following attribute to pass the display name into Coral Talk when creating a user account:
<div class="o-comments"
id="o-comments-stream"
data-o-component="o-comments"
data-o-comments-article-id="{article-id}"
data-o-comments-article-url="{optional-article-url}"
+ data-o-comments-display-name="{display-name}">
</div>No code will run automatically unless you are using the Build Service. You must either construct an o-comments object or fire the o.DOMContentLoaded event, which o-comments listens for.
Assuming you have an HTML element on the page to represent your comment stream or count:
import oComments from '@financial-times/o-comments';
const commentsElement = document.querySelector('#element');
const Comments = new oComments(commentsElement, {
articleId: 'article-id',
articleUrl: 'optional-article-url'
})Add useStagingEnvironment: true to the options if you want to use Coral staging environment.
If you want to initialise every comment stream or count element on the page (based on the presence of the attribute: data-o-component="o-comments"):
import oComments from '@financial-times/o-comments';
oComments.init();import '@financial-times/o-comments';
document.addEventListener('DOMContentLoaded', function() {
document.dispatchEvent(new CustomEvent('o.DOMContentLoaded'));
});Events are emitted during key events or interactions and can be listened to by listening for events on the document.
document.addEventListener('oComments.ready', (event) => {
console.log('This comments have rendered');
});These events are anything to do with the component itself.
These events are anything to do with comment interactions.
To keep tracking consistent across applications o-comments will emit o-tracking events for all of the events. If your application is already using o-tracking then then there is no need to do anything to track common events.
If you want to disable the o-tracking events and manage tracking / analytics yourself this can be done by passing the disableOTracking option to the o-comments instance.
Imperatively
import oComments from '@financial-times/o-comments';
const commentsElement = document.querySelector('#element');
const comments = new Comments(commentsElement, {
disableOTracking: true
});Declaratively
<div class="o-comments"
id="o-comments-stream"
data-o-component="o-comments"
data-o-comments-article-id="{article-id}"
data-o-comments-article-url="{optional-article-url}"
+ data-o-comments-disable-o-tracking="true">
</div>Include all styles for o-comments with the mixin oComments:
@include oComments()This component contains a sass file (/src/scss/coral-talk-iframe/main.scss) that provides custom styling for Coral Talk components inside their own iframe. That file must only be referenced from Coral Talk admin panel by specifying the path of the file in Origami Build Service.
Example: modules=o-comments@6.0.0-beta.24:/src/scss/coral-talk-iframe/main.scss
Encoded URL: https://www.ft.com/__origami/service/build/v2/bundles/css?modules%3Do-comments%406.0.0-beta.24%3A%2Fsrc%2Fscss%2Fcoral-talk-iframe%2Fmain.scss
If you have any questions or comments about this component, or need help using it, please either raise an issue, visit #origami-support or email Origami Support.
This software is published by the Financial Times under the MIT licence.