Skip to content

Playground

playground { } embeds a Kotlin Playground iframe — the audience can edit and run the snippet without leaving the slide.

Basic usage

fun playgroundBasic() {
  kslides {
    presentation {
      dslSlide {
        content {
          // Path or URL to a Kotlin source file shown in the editor.
          playground("src/main/kotlin/playground/HelloWorld.kt")
        }
      }
    }
  }
}

Configured

fun playgroundConfigured() {
  kslides {
    presentation {
      dslSlide {
        content {
          playground("src/main/kotlin/playground/HelloWorld.kt") {
            theme = PlaygroundTheme.DARCULA
            dataHighlightOnly = false
            from = 1
            to = 5
          }
        }
      }
    }
  }
}

Common options:

  • theme"default", "darcula", etc.
  • highlightOnly — render as a static highlight, with no run button.
  • lines — visible line range, e.g. "1-5".

Output behavior

  • Static site mode — kslides writes each playground iframe to docs/playground/<slug>.html.
  • HTTP mode — the Ktor server serves the iframe at a session-scoped URL, regenerating it on demand.

Tip: prefer include()

For longer programs, keep the code in its own .kt file and include() it:

playground {
  code = include("src/main/kotlin/playground/HelloWorld.kt")
}

This way the snippet stays compilable and refactorable as your real code evolves.