Skip to content

Commit

Permalink
Add field list shortcode and partial
Browse files Browse the repository at this point in the history
  • Loading branch information
jarrodmillman committed Feb 28, 2024
1 parent 699182a commit 758d99d
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
18 changes: 18 additions & 0 deletions assets/theme-css/lists.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
dl.field-list {
display: grid;
grid-template-columns: fit-content(30%) auto;
}

dl.field-list > dt {
font-weight: bold;
word-break: break-word;
padding-left: 0.5em;
padding-right: 5px;
}

dl.field-list > dd {
padding-left: 0.5em;
margin-top: 0em;
margin-left: 0em;
margin-bottom: 0em;
}
16 changes: 16 additions & 0 deletions layouts/partials/field-list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{{ $m := slice
(dict "term" "John" "def" 30)
(dict "term" "Will" "def" 28)
(dict "term" "Joey" "def" 24)
}}
<dl class="field-list">
{{ range $i, $entry := .entries }}
{{if (modBool $i 2)}}
<dt class="field-odd">{{ .term }}<span class="colon">:</span></dt>
<dd class="field-odd">{{ .def }}</dd>
{{else}}
<dt class="field-even">{{ .term }}<span class="colon">:</span></dt>
<dd class="field-even">{{ .def }}</dd>
{{end}}
{{end}}
</dl>
22 changes: 22 additions & 0 deletions layouts/shortcodes/field-list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{{/*

doc: Field lists

{{< field-list >}}
[[entry]]
term = "John"
def = 30

[[entry]]
term = "Will"
def = 28

[[entry]]
term = "Joey"
def = 24
{{< /field-list >}}

*/}}

{{ $entries := (index (.Inner | transform.Unmarshal) "entry") }}
{{ partial "field-list" (dict "ctx" . "entries" $entries) }}

0 comments on commit 758d99d

Please sign in to comment.