Containers allow you to group elements and apply specific themes or classes to a block of output.
cli_div(id = NULL, class = NULL, theme = NULL, .auto_close = TRUE, .envir = parent.frame()): Creates a generic container. If a theme is provided, it applies to all elements within this container.cli_end(id = NULL): Explicitly closes a container. If id is omitted, it closes the most recently opened container.
Auto-closing: By default, cli_div() containers close automatically when the calling function exits. To prevent this, set .auto_close = FALSE or provide a specific .envir.
# Custom theme in a div
d <- cli_div(theme = list(h1 = list(color = "cyan", "font-weight" = "bold")))
cli_h1("Custom title")
cli_end(d)
# Explicit closing
cnt <- cli_div()
cli_text("Inside container")
cli_end(cnt)