An easy way to use Clipboardjs in your project. Clipboardjs is a javascript only way to copy text to the clipboard.
Install this extension via composer. Add this line to your project’s composer.json
"supplyhog/yii2-clipboardjs" : "dev-master"
//Button to copy text
<?= \supplyhog\ClipboardJs\ClipboardJsWidget::widget([
'text' => "Hello World",
// 'label' => 'Copy to clipboard',
// 'htmlOptions' => ['class' => 'btn'],
// 'tag' => 'button',
]) ?>
//Button to copy text from input id
<?= \supplyhog\ClipboardJs\ClipboardJsWidget::widget([
'inputId' => "#input-url",
// 'cut' => false, // Cut the text out of the input instead of copy?
// 'label' => 'Copy to clipboard',
// 'htmlOptions' => ['class' => 'btn'],
// 'tag' => 'button',
]) ?>
Yes, you can use just the asset. php \supplyhog\ClipboardJs\ClipboardJsAsset::register($view)
It will auto init anything with the "clipboard-js-init" class.