From a6fca8fcd4624c52e604033afeb83afab6859781 Mon Sep 17 00:00:00 2001 From: razonyang Date: Tue, 19 Sep 2023 12:25:15 +0800 Subject: [PATCH] feat(icon-grid): add the item-attr-* dynamic parameters for attaching custom attributes on items --- layouts/partials/bootstrap/functions/attributes.html | 8 ++++++++ layouts/partials/bootstrap/icon-grid.html | 7 ++++++- 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 layouts/partials/bootstrap/functions/attributes.html diff --git a/layouts/partials/bootstrap/functions/attributes.html b/layouts/partials/bootstrap/functions/attributes.html new file mode 100644 index 0000000..0b4d9a7 --- /dev/null +++ b/layouts/partials/bootstrap/functions/attributes.html @@ -0,0 +1,8 @@ +{{- $attrs := slice }} +{{- $prefix := .Prefix | printf "%s-" }} +{{- range $name, $value := .Params }} + {{- if hasPrefix $name $prefix }} + {{- $attrs = $attrs | append (printf "%s=%s" (strings.TrimPrefix $prefix $name) $value) }} + {{- end }} +{{- end }} +{{- return $attrs }} diff --git a/layouts/partials/bootstrap/icon-grid.html b/layouts/partials/bootstrap/icon-grid.html index 1750812..d672bc7 100644 --- a/layouts/partials/bootstrap/icon-grid.html +++ b/layouts/partials/bootstrap/icon-grid.html @@ -7,11 +7,13 @@ }} {{- $border := true }} {{- $alignment := "start" }} +{{- $itemAttrs := slice }} {{- if .IsNamedParams }} {{- $key = .Get "data" }} {{- if isset .Params "linkText" }}{{ $linkText = .Get "linkText" }}{{ end }} {{- if isset .Params "border" }}{{ $border = .Get "border" }}{{ end }} {{- with .Get "alignment" }}{{ $alignment = . }}{{ end }} + {{- $itemAttrs = partial "bootstrap/functions/attributes" (dict "Params" .Params "Prefix" "item-attr") }} {{- else }} {{- $key = .Get 0 }} {{- end }} @@ -50,6 +52,7 @@
{{- $icon -}}{{- .title -}} @@ -59,7 +62,9 @@

{{ else }} -
+
{{- $icon -}}{{- .title -}}