diff options
author | Jhaura Wachsman <jw@jhaurawachsman.com> | 2020-07-16 20:03:51 +0300 |
---|---|---|
committer | Jhaura Wachsman <jw@jhaurawachsman.com> | 2020-07-16 20:03:51 +0300 |
commit | 6a1a598a2f4c66575e13cdb7af68cd26072256fe (patch) | |
tree | e791ae050818aa9fdcde3ee27899d55736549f2d | |
parent | 7fb077f688bd40aa1d7ef74c312183ec706d1bd5 (diff) |
Add HTML attribute "id" to Button element
-rw-r--r-- | layouts/partials/button.html | 5 | ||||
-rw-r--r-- | layouts/shortcodes/button.html | 5 |
2 files changed, 7 insertions, 3 deletions
diff --git a/layouts/partials/button.html b/layouts/partials/button.html index 093357c..3738425 100644 --- a/layouts/partials/button.html +++ b/layouts/partials/button.html @@ -3,8 +3,9 @@ {{- end }} {{- $text := .text -}} {{- $type := .type | default "default" -}} -{{- $svg := "" -}} +{{- $id := .id -}} {{- $class := "" -}} +{{- $svg := "" -}} {{- with .icon }} {{- $svg = printf "svg/%s.svg" . -}} {{- $svg = partial $svg (dict "class" "fill-current h-4 w-auto mr-2") -}} @@ -23,7 +24,7 @@ {{- $class = printf "%s rounded font-content-sans font-semibold %s %s %s py-2 px-4 %s" $class $textColor $bgColor $hoverColor $borderColor -}} {{- $class = trim $class " " -}} {{- if $href }} -<a class="{{ $class }}" href="{{ $href }}" role="button"> +<a{{ with $id }} id="{{ . }}"{{ end }} class="{{ $class }}" href="{{ $href }}" role="button"> {{- with $svg }} {{ . | safeHTML }} {{- end }} diff --git a/layouts/shortcodes/button.html b/layouts/shortcodes/button.html index a2b9de7..893cafb 100644 --- a/layouts/shortcodes/button.html +++ b/layouts/shortcodes/button.html @@ -2,18 +2,21 @@ {{- $type := "" -}} {{- $icon := "" -}} {{- $href := "" -}} +{{- $id := "" -}} {{- if .IsNamedParams }} {{- $text = .Get "text" -}} {{- $type = .Get "type" -}} {{- $icon = .Get "icon" -}} {{- $href = .Get "href" -}} +{{- $id = .Get "id" -}} {{- else }} {{- $text = .Get 0 -}} {{- $type = .Get 1 -}} {{- $icon = .Get 2 -}} {{- $href = .Get 3 -}} +{{- $id = .Get 4 -}} {{- end }} {{- if not $text }} {{- errorf "Missing required 'text'. Shortcode: 'button'." -}} {{- end }} -{{- partial "button" (dict "Site" $.Site "Page" . "text" $text "type" $type "icon" $icon "href" $href) -}} +{{- partial "button" (dict "Site" $.Site "Page" . "text" $text "type" $type "icon" $icon "href" $href "id" $id) -}} |