Arif
September 22, 2023, 8:56pm
1
New topic from this question . I would like to split the duplicate tailwind styles as follows:
A var for all the classes appearing in all three instances.
A var for classes only appearing in the active states.
A var for classes only appearing in the default state.
See Example below
{{- var1 := "bg-blue-500 text-red-200" }}
{{- var2 := "hover:bg-blue-400 border-r" }}
{{- var3 := "hover:bg-blue-300 ml-4" }}
Then in the dict
part of class
, I would like to merge var1
to var2
for both active states and var1
to var3
for the default state so that the styles now appear together. Which is the correct way to do it? cc @jmooring .
...
{{ $var1 := "class-1" }}
{{ $var2 := "class-2" }}
{{ $var3 := "class-3" }}
{{ $activeState := printf ("%s %s") $var1 $var2 }}
{{ $defaultState := printf ("%s %s") $var1 $var3 }}
{{- $page := .page }}
{{- range .menuEntries }}
{{- $attrs := dict "class" $defaultState "href" .URL }}
{{- if $page.IsMenuCurrent .Menu . }}
{{- $attrs = merge $attrs (dict "class" $activeState "aria-current" "page") }}
{{- else if $page.HasMenuCurrent .Menu .}}
{{- $attrs = merge $attrs (dict "class" $activeState "aria-current" "true") }}
{{- end }}
...
1 Like
Arif
September 22, 2023, 9:24pm
3
Thanks! Forgot about printf
. I played with union
and append
but both presented broken strings.
system
Closed
September 24, 2023, 9:24pm
4
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.