Skip to contents

[Stable] The parts a template is made of. tip_title() is the first line, tip_text() a paragraph of markdown, tip_badge() a short label, tip_fields() a list of label and value pairs, and tip_code() a piece of code shown as text. Text and values may hold placeholders, {{ field }} or {{ field | number:2 }}, filled from the record of the item the tip belongs to. A placeholder names one field, matched exactly (dots and spaces allowed), and takes one filter at most: number (digits after the point, rounded as R does) or percent (the value times 100, then digits, then a percent sign). A value that is missing or blank shows a dash. There is no way to write a literal {{ yet.

Usage

tip_title(text)

tip_text(text)

tip_badge(text, status = NULL)

tip_fields(...)

tip_code(field, language = NULL, copy = FALSE)

Arguments

text

One string, with placeholders if you like. In tip_text() it is markdown (strong, emphasis, code, links, short lists), and a value put in by a placeholder is never read as markdown.

status

What the badge says about its item, or NULL for a plain badge: one of "success", "warning", "danger" or "info", the words bslib uses, or a placeholder such as "{{ tone }}" filled from the record. Any other fixed word is an error. When filled from a record, one of the four words colours the badge and any other value shows a plain badge. The badge is coloured from the page's Bootstrap colours for that status (with plain colours on a page without Bootstrap), and its text should say the same thing, because colour alone is not enough. A block written as a plain list, list(type = "badge", text = "a", tone = "info"), uses the engine's name for it, tone, with the same rule.

...

Named strings for tip_fields(): each name is a label (plain text) and each value a string that may hold placeholders, as in tip_fields(Records = "{{ records | number:0 }}").

field

One string: the name of the record field that holds the code. The code is shown as text, never run, and never filled in by placeholders.

language

One string naming the code's language, or NULL.

copy

TRUE asks for a Copy button under the code, which lives in a tip that stays open: give the tag that has this template pin = TRUE or pin = "click" in tip_on(), or the button never shows. The button copies the code as text, also on a page that is not served over https (where the browser's clipboard is closed to a page, the copy is done the older way), and says "Copied" or "Copy failed" beside the button. With events = "copy" in tip_on(), the server reads each press as input$<id>_copy.

Value

A block, to give to tip_template().

Examples

tip_title("{{ label }}")
#> <tip block: title>
tip_text("**{{ differences | number:0 }}** differences")
#> <tip block: text>
tip_badge("{{ status }}", status = "warning")
#> <tip block: badge>
tip_fields(Records = "{{ records | number:0 }}", Files = "{{ files }}")
#> <tip block: fields>
tip_code("sql", language = "sql")
#> <tip block: code>