Skip to content

Commit 1d95670

Browse files
Support grid items and cards (#512)
1 parent fc4fc35 commit 1d95670

1 file changed

Lines changed: 51 additions & 13 deletions

File tree

layouts/shortcodes/grid1.html

Lines changed: 51 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,51 @@
22

33
doc: Grids.
44

5-
{{< grid1 columns="1 2 2 4">}}
5+
{{< grid1 columns="1 2 3 4" >}}
66

7-
[[card]]
7+
[[item]]
8+
type = ''
9+
body = 'A'
10+
11+
[[item]]
12+
type = ''
13+
body = 'B'
14+
15+
[[item]]
16+
type = ''
17+
body = 'C'
18+
19+
[[item]]
20+
type = ''
21+
body = 'D'
22+
23+
{{< /grid1 >}}
24+
25+
{{< grid1 columns="1 2 2 4" >}}
26+
27+
[[item]]
28+
type = 'card'
829
title = 'Only title'
930

10-
[[card]]
31+
[[item]]
32+
type = 'card'
1133
body = '''
1234
Only body.
1335

1436
But with multiple text paragraphs.
1537
'''
1638

17-
[[card]]
39+
[[item]]
40+
type = 'card'
1841
title = 'Heading and body'
1942
body = '''
2043
Content of the third card.
2144

2245
{{< badge primary >}}Sample badge{{< /badge >}}
2346
'''
2447

25-
[[card]]
48+
[[item]]
49+
type = 'card'
2650
title = 'A card with a dropdown menu'
2751
body = '''
2852
{{< dropdown >}}
@@ -32,13 +56,15 @@
3256
{{< /dropdown >}}
3357
'''
3458

35-
[[card]]
59+
[[item]]
60+
type = 'card'
3661
header = 'Header'
3762
title = 'Card Title'
3863
body = 'Card content'
3964
footer = 'Footer'
4065

41-
[[card]]
66+
[[item]]
67+
type = 'card'
4268
header = 'A clickable image card'
4369
link = 'https://example.com'
4470
body = '''{{< image >}}
@@ -47,15 +73,17 @@
4773
align = 'center'
4874
{{< /image >}}'''
4975

50-
[[card]]
76+
[[item]]
77+
type = 'card'
5178
header = 'A clickable figure card'
5279
link = 'https://example.com'
5380
body = '''{{< figure
5481
src="https://source.unsplash.com/200x200/daily?cute+puppy"
5582
alt="Cute puppies"
5683
>}}'''
5784

58-
[[card]]
85+
[[item]]
86+
type = 'card'
5987
link = 'https://example.com'
6088
body = '''{{< figure
6189
src="https://source.unsplash.com/200x200/daily?cute+puppy"
@@ -68,7 +96,6 @@
6896
*/}}
6997

7098
<div class="sd-container-fluid sd-mb-4">
71-
{{ $cards := "" }}
7299
{{- with .Get "columns" -}}
73100
{{ $columns := split . " " }}
74101
{{ $xs := index $columns 0 }}
@@ -79,16 +106,18 @@
79106
{{- else }}
80107
<div class="sd-row sd-row-cols-auto sd-row-cols-xs-auto sd-row-cols-sm-auto sd-row-cols-md-auto sd-row-cols-lg-auto">
81108
{{- end }}
109+
{{ $items := "" }}
82110
{{- with .Get "file" -}}
83111
{{ with $.Page.Resources.Get . | transform.Unmarshal }}
84-
{{ $cards = (index . "card") }}
112+
{{ $items = (index . "item") }}
85113
{{ else }}
86114
{{ errorf "Unable to get page resource %q" . }}
87115
{{ end }}
88116
{{- else }}
89-
{{ $cards = (index (.Inner | transform.Unmarshal) "card") }}
117+
{{ $items = (index (.Inner | transform.Unmarshal) "item") }}
90118
{{- end }}
91-
{{- range $key, $d := $cards -}}
119+
{{- range $key, $d := $items -}}
120+
{{ if eq $d.type "card" }}
92121
<div class="sd-col sd-d-flex-row">
93122
{{- with $d.link }}
94123
<div class="sd-card sd-w-100 sd-shadow-sm sd-card-hover">
@@ -120,6 +149,15 @@
120149
{{- end }}
121150
</div>
122151
</div>
152+
{{ else }}
153+
<div class="sd-col sd-d-flex-column">
154+
<p>
155+
{{- with (trim .body "\n") }}
156+
{{ . | markdownify }}
157+
{{- end }}
158+
</p>
159+
</div>
160+
{{ end }}
123161
{{- end }}
124162
</div>
125163
</div>

0 commit comments

Comments
 (0)