Look and Feel

Part Overrides with Custom Elements ​

A part override can be the name of a custom element you've registered, rather than a function. That suits a site that already builds its interface from custom elements, or a part that needs its own state and behaviour, such as a badge with a tooltip. Comments draws your element in the part's place and keeps it updated with the part's data, and everything else about the thread stays as it was.

A Verified Badge ​

Suppose some commenters carry a verified badge, which a site adds on the server with the plugin's Comments::EVENT_DEFINE_BADGES event, and you want a tick and a tooltip on it. This element draws every badge, keeping Comments' own badge classes so its stylesheet still styles them:

js
class CommentBadge extends HTMLElement {
    // Comments sets each of the part's context keys as a property, every time the part is drawn.
    set badge(badge) {
        const verified = badge.type === 'verified';

        this.className = `comments__badge comments__badge--${badge.type.replace(/[^\w-]/g, '')}`;
        this.textContent = verified ? `✓ ${badge.label}` : badge.label;
        this.title = verified ? 'This commenter has bought from us.' : '';
    }
}

customElements.define('acme-comment-badge', CommentBadge);
js
document.querySelector('verbb-comments').parts = { badge: 'acme-comment-badge' };

Comments creates the element once for each badge and, each time the badge is drawn, sets every key of the part's context on it as a property, such as badge, comment, viewer, labels, actions, controlAttributes, html and defaultRender. A setter, as above, or a library such as Lit that turns properties into renders, lets the element follow along. The element sits in the thread's light DOM, so Comments' stylesheet and yours reach it. Draw any text from a comment or a commenter as text, as textContent does, never as HTML.

Simpler Overrides as Functions ​

A custom element is worth registering when the part has state or behaviour of its own. For markup alone, a function is shorter and needs no registration:

js
document.querySelector('verbb-comments').parts = {
    badge: ({ badge, html, defaultRender }) => badge.type === 'verified'
        ? html`<span class="badge badge-success">✓ ${badge.label}</span>`
        : defaultRender(),
};

What an Override Is Given ​

A function is given the part's context as its argument, and a custom element gets each key as a property, with the part's own data from the table below.

KeyWhat it is
labelsThe thread's translated wording, keyed as Configuring Threads lists.
actionsFor a comment's parts, vote(vote), reply(), edit(), delete(), report(), copyLink(), moderate(action), toggleReplies() and loadReplies(), bound to the comment. The thread's own parts get an empty object.
controlAttributes(name)The attributes of one of the ten controls with your themeConfig applied, for a button or link your override draws.
htmllit-html's template tag, which escapes everything it inserts.
defaultRender()Comments' own markup for the part, to wrap or fall back to.

A comment's parts also get comment, the comment's data in the data API's shape, permissions, what the person reading may do with it (such as canReply, canVote and their own vote), and viewer, who's reading.

If an override throws, the error is logged in the browser console and Comments' own markup is drawn in its place, so the rest of the thread keeps working.

Overriding the Whole Comment ​

A function override of the comment part replaces the comment's list item along with everything in it. It has to return an <li>, because it sits in the thread's list, and it has to draw form(), where Reply and Edit open their form, and replies(), or those stop working. Overriding the smaller parts inside a comment, such as meta, content and actions, keeps all of that for you, and a framework component override of comment draws inside Comments' own list item.

The Parts ​

PartGroupWhat it drawsIts own context
headerThreadThe heading with the count, the sort options, Follow and a moderator’s summary of held and reported commentsviewer, conversation and state
emptyThreadWhat a thread with no comments saysviewer, conversation and state
showButtonThreadThe Show comments button for the button load modeviewer, conversation and state
loadingThreadThe loading line while the thread’s data is on its wayviewer, conversation and state
noticeThreadWhy nobody can post, such as a closed thread’s noticenotice, the text, with viewer, conversation and state
commentCommentThe whole commentcomment, permissions, viewer, conversation, actions, and form() and replies(), which the override must draw
avatarCommentThe author’s avatarcomment, permissions, viewer, conversation and actions
authorNameCommentThe author’s namecomment, permissions, viewer, conversation and actions
badgeCommentOne of the author’s badges, once for eachbadge (its type and label), with the comment’s context
metaCommentThe date and permalink, inline custom fields and the edited notecomment, permissions, viewer, conversation and actions
contentCommentThe comment’s textcomment, permissions, viewer, conversation and actions
fieldsCommentThe custom fields shown under the text, as a labelled listfields, the comment’s entries shown under its text, with the comment’s context
actionsCommentVotes, Reply and the ··· menucomment, permissions, viewer, conversation and actions
reviewCommentA moderator’s review box on a held or reported commentmoderation, the comment’s moderation details, with the comment’s context
placeholderCommentWhat stands in for a comment that’s no longer shown but still has repliescomment, permissions, viewer, conversation and actions
joinEditorThe sign-in card a guest sees in place of the comment boxviewer, conversation and state
postingAsEditor“Posting as” and the member’s badges, above a member’s comment boxviewer
formFieldsEditorThe custom fields the form asks for, once for those above the text and once for those below itfields, the descriptions of the fields in this group, and position, above or below

The comment form itself, the comment box, the rich text editor and the report form can't be overridden, because they carry spam protection, the editor's loading and keyboard focus. Their look is reached through styling, and custom fields on the form and the comment through field overrides.

Removing Something ​

An override can return nothing, but to remove a feature, turn it off in the plugin's settings first. A setting also stops the server offering the feature, so hiding the vote buttons with an empty actions override would still let anyone vote through the data API, whereas setting Interaction Mode to None removes voting altogether.

In Twig ​

A thread Craft renders can take custom elements for its field overrides through craft.comments.render(), because the mount point carries their names as data. Part overrides, which can be functions, are given in JavaScript through Comments.configure(), with the element's name in place of a function:

js
document.addEventListener('DOMContentLoaded', () => {
    window.Comments.configure({ parts: { badge: 'acme-comment-badge' } });
});
Last updated: Nov 18, 2026, 12:27 PM