mirror of
https://github.com/gethinode/hinode.git
synced 2025-10-17 23:13:11 +00:00
74 lines
2.0 KiB
HTML
74 lines
2.0 KiB
HTML
{{/* Adapted from https://gohugo.io/render-hooks/tables/ */}}
|
|
|
|
<!-- Ensure presence of `.table` class attribute to trigger Bootstrap styling -->
|
|
{{ $attr := .Attributes }}
|
|
{{ $class := split $attr.class " " }}
|
|
{{ if not (in $class "table") }}
|
|
{{ $attr = merge $attr (dict "class" (trim (delimit ($class | append "table") " ") " ")) }}
|
|
{{ end }}
|
|
|
|
{{ $wrap := in $class "table-wrap" }}
|
|
{{ $align := dict "left" "start" "center" "center" "right" "end" }}
|
|
|
|
{{ $header := "" }}
|
|
<table
|
|
{{- range $k, $v := $attr }}
|
|
{{- if $v }}
|
|
{{- printf " %s=%q" $k $v | safeHTMLAttr }}
|
|
{{- end }}
|
|
{{- end }}>
|
|
<thead>
|
|
{{- range .THead }}
|
|
{{ $length := len . }}
|
|
{{ if $wrap }}
|
|
<tr>
|
|
{{- range . | first (sub $length 1) }}
|
|
<th {{ with .Alignment }}class="text-{{ index $align . }}"{{ end }}>
|
|
{{- .Text -}}
|
|
</th>
|
|
{{- end }}
|
|
{{- range . | last 1 }}
|
|
{{ $header = .Text }}
|
|
{{ end }}
|
|
</tr>
|
|
{{ else }}
|
|
<tr>
|
|
{{- range . }}
|
|
<th {{ with .Alignment }}class="text-{{ index $align . }}"{{ end }}>
|
|
{{- .Text -}}
|
|
</th>
|
|
{{- end }}
|
|
</tr>
|
|
{{ end }}
|
|
{{- end }}
|
|
</thead>
|
|
<tbody>
|
|
{{- range .TBody }}
|
|
{{ $length := len . }}
|
|
{{ if $wrap }}
|
|
<tr>
|
|
{{- range . | first (sub $length 1) }}
|
|
<td class="{{ with .Alignment }}text-{{ index $align . }}{{ end }} table-border-bottom-wrap">
|
|
{{- .Text -}}
|
|
</td>
|
|
{{- end }}
|
|
</tr>
|
|
<tr>
|
|
{{- range . | last 1 }}
|
|
<td class="{{ with .Alignment }}text-{{ index $align . }}{{ end }}" colspan="{{ (sub $length 1) }}">
|
|
{{- .Text -}}
|
|
</td>
|
|
{{ end }}
|
|
</tr>
|
|
{{ else }}
|
|
<tr>
|
|
{{- range . }}
|
|
<td {{ with .Alignment }}class="text-{{ index $align . }}"{{ end }}>
|
|
{{- .Text -}}
|
|
</td>
|
|
{{- end }}
|
|
</tr>
|
|
{{ end }}
|
|
{{- end }}
|
|
</tbody>
|
|
</table> |