Preview
Enable previews for fields in the edit or create page, such as video, image, or custom HTML previews.
The Preview feature allows displaying a preview of a field's data when editing or adding a record. This is useful for previewing videos, images, or any other content.
To define a custom Preview, create a class extending KtorAdminPreview:
class VideoPreview : KtorAdminPreview() {
override val key: String
get() = "video_preview"
override fun createPreview(tableName: String, name: String, value: Any?): String? {
return value?.toString()?.let { video ->
expandable(title = "Video preview") {
video(src = video)
}
}
}
}key: String→ A unique identifier for the preview.createPreview(tableName: String, name: String, value: Any?): String?→ Generates an HTML string for the preview.tableName→ The name of the table.name→ The column name or field name in collections.value→ The stored value of the field.Returns → A String containing HTML content for the preview. If
nullis returned, no preview will be displayed.
Prebuilt Template Functions
Several helper functions are available to simplify preview creation:
expandable(title: String, content: () -> String): String→ Creates an expandable section.video(src: String): String→ Generates an HTML video element.image(src: String): String→ Generates an HTML image element.
Registering the Preview
Using @Preview on Fields
@Preview on FieldsApply @Preview to fields requiring a preview:
This ensures a video preview is displayed when editing or adding a record.
Last updated