Templates
The Chat component provides extensive template customization options that allow you to control the rendering of various chat elements.
By using templates, you can adjust the default appearance and behavior of messages, file attachments, suggestions, and other UI components to match your application's design and requirements. For more information on the capabilities and syntax of the templates, see the Using Client Templates article.
Overview
The Chat component supports the following templates:
- Message Templates—Control how individual messages and message groups are rendered.
- Files Template—Customize the display of file attachments within messages.
- Header Items—Define custom content for the chat header area.
- Suggestion Templates—Modify suggested actions and message suggestions layout.
- Timestamp Template—Control how date and time separators are displayed.
Message Templates
The Chat component offers comprehensive message templating capabilities that enable you to customize the visual presentation and behavior of individual messages, message groups, and reference elements within the chat interface.
MessageTemplate
The MessageTemplate
method controls the rendering of individual messages within the chat interface. The templating option receives comprehensive data about the message and related functionality, allowing for complete customization of message appearance including text content, timestamps, author information, and interactive elements.
The following example demonstrates how to use the MessageTemplateHandler()
option to customize the layout of the Chat messages.
@(Html.Kendo().Chat()
.Name("chat")
.MessageTemplateHandler("getMessageLayout")
)
MessageGroupTemplate
The MessageGroupTemplate()
option controls how message groups are rendered when multiple consecutive messages come from the same author. Message groups help organize conversations by visually grouping messages together, reducing visual clutter and improving readability in busy chat environments. The templating option is particularly useful for customizing how author information is displayed, implementing conversation threading, or creating distinct visual styles for different types of message groups.
The following example demonstrates how to use the MessageGroupTemplateHandler()
option to customize the rendering of the message groups.
@(Html.Kendo().Chat()
.Name("chat")
.MessageGroupTemplateHandler("getMessageGroupLayout")
)
MessageReferenceTemplate
The MessageReferenceTemplate()
method customizes the rendering of the message references that are used for reply chains and pinned message indicators within the chat interface. The templating option displays contextual information about referenced messages, allowing users to understand the relationship between current messages and previously sent content. You can use the template to create visually distinct reference displays, implement custom styling for different reference types (replies versus pins), or add interactive elements that allow users to navigate to the original referenced message.
The outermost element must always have the
ref-chat-message-reference-pin-wrapper
attribute.
The following example demonstrates how to use the MessageReferenceTemplateHandler()
option to customize the appearance of the message references.
@(Html.Kendo().Chat()
.Name("chat")
.MessageReferenceTemplateHandler("getMessageReferenceLayout")
)
Files Template
The FilesTemplate()
method customizes how file attachments are displayed within chat messages, providing complete control over the presentation and interaction of shared files. The templating option allows you to create custom file previews, display file metadata such as size, type, and upload date.
The outermost element must always have the
ref-chat-file-wrapper
attribute.
The following example demonstrates how to use the FilesTemplateHandler()
option to customize the appearance of the attachments in the message.
@(Html.Kendo().Chat()
.Name("chat")
.FilesTemplateHandler("getFilesLayout")
)
Header Items
The HeaderItems()
configuration allows you to define custom content for the chat header area using flexible template functions that return HTML content. Each header item can include logos, titles, navigation elements, action buttons, or any other UI components that enhance the chat experience and provide contextual information to users.
@(Html.Kendo().Chat()
.Name("chat")
.HeaderItems(items =>
{
items.Add().Type(AppBarItemType.ContentItem).Template("<strong>Careers portal chat</strong>");
items.Add().Type(AppBarItemType.Spacer);
items.Add().Type(AppBarItemType.ContentItem).Template(Html.Kendo().Template()
.AddComponent(btn => btn
.Button()
.Name("new-chat")
.Text("New Chat")
.Icon("plus")
));
})
)
Suggestion Templates
You can modify the default layout of the Message Suggestions and Suggested Actions elements. For more information on the suggestion mechanisms of the Chat, refer to the Quick Actions documentation.
SuggestedActionsTemplate
The SuggestedActionsTemplate()
option customizes the rendering of suggested actions that appear with specific messages, typically originating from chatbots, automated systems, or AI assistants. These suggested actions provide users with quick response options, eliminating the need to type common replies and improving conversation flow by offering contextually relevant choices.
The following example demonstrates how to customize the default appearance of the suggested actions using a JavaScript handler.
@(Html.Kendo().Chat()
.Name("chat")
.SuggestedActionsTemplateHandler("getActionTemplate")
)
SuggestionsTemplate
The SuggestionsTemplate()
option customizes the rendering of message suggestions that appear above the chat input area, providing users with quick reply options and commonly used phrases. The suggestions help streamline conversations by offering pre-defined responses that users can select instead of typing, which is particularly useful for customer service scenarios or repetitive interactions.
The following example demonstrates how to customize the default appearance of the suggestion messages.
@(Html.Kendo().Chat()
.Name("chat")
.Suggestions(suggestions => {
suggestions.Add().Text("Check Weather");
suggestions.Add().Text("Set Reminder");
suggestions.Add().Text("Play Music");
suggestions.Add().Text("Get News");
suggestions.Add().Text("Help");
})
.SuggestionsTemplateHandler("getSuggestionsTemplate")
)
Timestamp Template
The TimestampTemplate()
method controls how date and time separators are displayed between message groups, providing crucial temporal context that helps users navigate through conversation history. The templating option allows you to customize the appearance of time dividers that automatically appear when there are significant time gaps between messages, making it easier for users to understand when different parts of the conversation took place.
The following example demonstrates how to use the TimestampTemplateHandler()
option to style the timestamp elements.
@(Html.Kendo().Chat()
.Name("chat")
.TimestampTemplateHandler("getTimeStampFormat")
)