{copy}
A text in a code block with a button that copies it to the clipboard.
Syntax
{copy 'text'}
{copy $value, label='Copy command'}
{copy label='Copy'} ... {/copy}
Parameters
-
text - The text to show and copy - a value, escaped. Not used by the pair form, whose content is the text.
Options
-
label -
The text of the button,
Copywhen not given.
Description
{copy} shows a text in a <pre><code> block that selects as a whole with one click, and beside it a button that puts the text on the clipboard. The button needs scripting: a small script, written once per page (with the CSP nonce when one is asked for), copies through navigator.clipboard, or through the selection on a page over plain http, and says "Copied" on the button and to a screen reader. Without scripting there is no button and the text is selected and copied by hand.
The single tag takes the text as its first parameter - a value, so it is escaped and never read as template. As a pair the content is the text: it is rendered first, then trimmed, so fields and tags inside it are resolved - {copy}padSqlDatabase={$app}.sqlite{/copy}.
label= sets the text of the button. A single {copy} without a text is an error under the strict check. The colours are --pad-copy-accent, -text, -muted, -line, -surface and -done on .pad-copy.
Examples
A command to copy
The text as a parameter - a literal, and a value with its own button label.
<p>Add the package:</p>
{copy 'composer require pad/pad'}
<p>Or start a fresh application:</p>
{copy $command, label='Copy command'}
<?php
$command = 'pad new shop && pad serve 8000';
?>
Add the package:
composer require pad/pad
Or start a fresh application:
pad new shop && pad serve 8000
Rendered content
The pair form - the content renders first, so a field of the page goes into the copied text.
{set $app = 'shop'}
{copy label='Copy settings'}
padSqlDriver=sqlite
padSqlDatabase={$app}/{$app}.sqlite
{/copy}
padSqlDriver=sqlite
padSqlDatabase=shop/shop.sqlite
See also
- {highlight} Colours source code on the server - PAD, PHP, HTML, CSS, JavaScript, JSON, YAML, SQL or shell - with optional line numbers and marked lines.
- {source} Shows the files behind a page as tabs, each coloured as highlight colours it - the code shown is the code that runs.
- {modal} A dialog over the page with the button that opens it - works with and without JavaScript.