-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathButtonShortcode.php
38 lines (29 loc) · 1.28 KB
/
ButtonShortcode.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
namespace Grav\Plugin\Shortcodes;
use Grav\Common\Utils;
use Thunder\Shortcode\Shortcode\ShortcodeInterface;
class ButtonShortcode extends Shortcode
{
public function init()
{
$this->shortcode->getHandlers()->add('button', function (ShortcodeInterface $sc) {
// Get shortcode content and parameters
$str = $sc->getContent();
$buttonurl = $sc->getParameter('url', $sc->getBbCode());
$buttontarget = $sc->getParameter('target', $sc->getBbCode());
$buttonstyle = $sc->getParameter('style', $sc->getBbCode());
$buttonsize = $sc->getParameter('size', $sc->getBbCode());
$buttonclasses = $sc->getParameter('classes', $sc->getBbCode());
$buttonlabel = $sc->getParameter('label', $sc->getBbCode());
if (empty($buttonsize)) {
$buttonsize = "btn";
} else {
$buttonsize = "btn btn-" . $buttonsize;
}
if (!empty($buttonurl) && !empty($buttonlabel)) {
$output = '<p><a href="' . $buttonurl . '" target="' . $buttontarget . '" class="' . $buttonsize . ' btn-' . $buttonstyle . ' ' . $buttonclasses . '">' . $buttonlabel . '</a></p>';
return $output;
}
});
}
}