Configuring Threads
Comments.configure() gives settings to every thread on the page, such as your design system's button classes, a part override or different wording. It's the same on window.Comments from the plugin's script, on the package's Comments export, and as the configure export on its own. Settings can be given at any time, before or after the threads start, and threads already drawn redraw with them.
document.addEventListener('DOMContentLoaded', () => {
window.Comments.configure({
theme: 'auto',
labels: {
empty: 'Nobody has said anything yet.',
},
themeConfig: {
primaryButton: { resetClass: true, attributes: { class: 'btn btn-primary' } },
},
});
});Every thread on the page switches to the automatic theme, an empty thread says “Nobody has said anything yet.”, and Post and the other main buttons use your btn btn-primary classes in place of Comments' own button styling.
The Settings
| Setting | What it does |
|---|---|
themeConfig | Classes and attributes for the ten controls, covered in themeConfig for Controls. |
parts | Part overrides by name, covered in Part Overrides. |
fields | Custom field overrides by handle, covered in Field Overrides. |
labels | Wording to use instead of the site's translations, below. |
theme | light, dark, auto or none, covered in Dark Mode. |
darkSelector | A selector, such as html.dark, that switches every thread to dark while it matches <html>. |
loadMode | When a thread without a load mode of its own loads, covered in Lazy Loading. |
loadEditor | A function that loads Editor for rich comments, resolving once <verbb-editor> is defined, covered in Bundling in Your Own Build. |
auth | How the person is identified, from @verbb/comments-core, covered in Signing In. Defaults to Craft's session cookie. |
nonce | A Content Security Policy nonce for the scripts and stylesheets a thread loads, such as Editor's and the spam protection's challenges. |
fetch | A fetch to use instead of the global one. |
How Settings Combine
Each configure() call merges with the ones before it. themeConfig merges control by control and attribute by attribute, parts by part name, fields by handle and by input or display, and labels by key, so a later call can add one part override without losing another. Every other setting is replaced by the latest value given.
A thread can get settings from three places, and later ones win.
- Its mount point, from the options passed to
craft.comments.render()or set inconfig/comments.php. Comments.configure()orstartComments().- The thread's own options, from
mountThread(), a<verbb-comments>element's properties or a React or Vue component's props.
loadMode is the exception, because a thread's own load mode from render() always wins over configure()'s. auth and fetch are read when a thread starts, so changing them in configure() reaches only threads that start afterwards.
Settings reach threads drawn by the plugin's script, by your own call to startComments(), and by code that mounts threads through @verbb/comments-browser/renderer, such as the web components and the React and Vue packages, including settings given before that code was loaded. Once one copy of the script is running on the page, configure() in another copy passes its settings to the one that's running.
Labels
Every word the thread shows comes from the site's translations in Craft's comments category, so changing wording per site and language is usually done with a static translation file, as the plugin's Text & Translations explains. labels is for wording that belongs to your JavaScript rather than your Craft site, such as an app on another domain that wants its own tone. It takes the keys below, and wins over the site's translations.
window.Comments.configure({
labels: {
post: 'Send',
editorPlaceholder: 'What do you think?',
charactersLeft: '{count} to go',
},
});Placeholders such as {count} and {name} are filled in by the renderer, so keep them in your wording. A label set to an empty string is ignored, and the site's own wording is used instead.
The keys marked “No” in the last column aren't in Craft's translation list. The renderer uses its own English for them unless you give labels.
| Key | Default text | Translated through Craft |
|---|---|---|
commentCountOne | 1 comment | Yes |
commentCountOther | {count} comments | Yes |
showComments | Show comments | Yes |
showCommentsCount | Show comments ({count}) | Yes |
loading | Loading comments… | Yes |
loadMore | Load more comments | Yes |
empty | No comments yet. | Yes |
beFirst | Be the first to comment. | Yes |
closed | Comments are closed. | Yes |
sortLabel | Sort comments | Yes |
sortNewest | Newest | Yes |
sortOldest | Oldest | Yes |
sortTop | Top | Yes |
reply | Reply | Yes |
replyTo | Reply to {name}… | Yes |
replyingTo | Replying to | Yes |
cancelReply | Cancel reply | Yes |
cancel | Cancel | Yes |
post | Post | Yes |
posting | Posting… | Yes |
save | Save comment | Yes |
edit | Edit | Yes |
edited | Edited | Yes |
delete | Delete | Yes |
deleteConfirm | Delete this comment? This can’t be undone. | Yes |
like | Like | Yes |
likes | Likes | Yes |
upvote | Upvote | Yes |
downvote | Downvote | Yes |
score | Score | Yes |
report | Report… | Yes |
reportTitle | Report this comment | Yes |
reportReason | What’s wrong with it? | Yes |
reportDetails | Anything else? | Yes |
reportDetailsHint | Optional. Only moderators see this. | Yes |
sendReport | Send report | Yes |
reportSent | Thanks for reporting this. A moderator will take a look. | Yes |
reportWithdrawn | Report withdrawn. | Yes |
close | Close | Yes |
moreActions | More actions | Yes |
copyLink | Copy link | Yes |
linkCopied | Link copied. | Yes |
showReplies | Show replies | Yes |
hideReplies | Hide replies | Yes |
loadMoreReplies | Load more replies | Yes |
guest | Guest | Yes |
commentBy | Comment by | Yes |
unavailable | Comment unavailable. | Yes |
awaitingApproval | Waiting for approval. Only you can see this until a moderator approves it. | Yes |
editorPlaceholder | Add to the conversation… | Yes |
editPlaceholder | Edit your comment… | Yes |
yourComment | Your comment | Yes |
writeSomethingFirst | Write something first. | Yes |
tooLong | Too long by {count} characters | Yes |
charactersLeft | {count} characters left | Yes |
characterCount | {count} of {limit} characters | Yes |
draftSaved | Draft saved | Yes |
draftRestored | Restored your draft from {time}. | Yes |
discardConfirm | Discard what you’ve written? | Yes |
discard | Discard | Yes |
uploadInProgress | Please wait for your upload to finish. | Yes |
joinTitle | Join the conversation | Yes |
signIn | Sign in | Yes |
signInToComment | Sign in to comment. | Yes |
signInOrGuest | Sign in to comment and hear about replies, or post as a guest. | Yes |
commentAsGuest | Comment as a guest | Yes |
postingAs | Posting as | Yes |
yourDetails | Your details | Yes |
yourName | Your name | Yes |
yourEmail | Your email | Yes |
notShownPublicly | Not shown publicly | Yes |
replyEmails | Email me when someone replies. We’ll ask you to confirm your address first. | Yes |
follow | Follow | Yes |
following | Following | Yes |
followByEmail | Follow by email | Yes |
error | Something went wrong. Please try again. | Yes |
tryAgain | Try again | Yes |
moderator | Moderator | Yes |
moderatorView | Moderator view. | Yes |
reviewInComments | Review in Comments | Yes |
heldCount | {count} held | Yes |
reportedCount | {count} reported | Yes |
showHeld | Show held | Yes |
hideHeld | Hide held | Yes |
approve | Approve | Yes |
markSpam | Mark as spam | Yes |
notSpam | Not spam | Yes |
remove | Remove | Yes |
restore | Restore | Yes |
keep | Keep | Yes |
spam | Spam | Yes |
gif | GIF | Yes |
gifAdd | Add a GIF | Yes |
gifSearch | Search GIPHY | Yes |
gifResults | GIFs | Yes |
gifRemove | Remove GIF | Yes |
gifEmpty | No GIFs found. | Yes |
gifPoweredBy | Powered by GIPHY | Yes |
gifUnavailable | GIFs can’t be loaded right now. | Yes |
foldedReports | Comment marked as inappropriate | Yes |
foldedDownvotes | Comment hidden due to low rating | Yes |
showFolded | Show comment | Yes |
authorScore | Total votes across this user’s comments | Yes |
comments | Comments | Yes |
moderation | Moderation | Yes |
onThisPage | on this page | Yes |
hold | Hold | Yes |
removedNote | Removed · only moderators see this | Yes |
chooseOption | Choose… | Yes |
addFiles | Add files | Yes |
addFile | Add a file | Yes |
removeFile | Remove | Yes |
retryUpload | Try {name} again | Yes |
uploading | Uploading… | Yes |
uploaded | {name} uploaded. | Yes |
uploadFailed | {name} didn’t upload. | Yes |
fileRemoved | {name} removed. | Yes |
uploadLimits | Up to {count} files, {size} each. | Yes |
uploadLimit | Up to {size}. | Yes |
fileTypeNotAllowed | {name} can’t be added here. Choose {types}. | Yes |
fileTooLarge | {name} is larger than {size}. | Yes |
tooManyFiles | You can add up to {count} files here. | Yes |
formFailed | The comment form couldn’t load. Please try again. | No, labels only |
uploadsFailed | Remove or try again the files that didn’t upload, so nothing is left out. | No, labels only |
uploadsUnavailable | Files can’t be added right now. | No, labels only |