matrix-spec/layouts/_shortcodes/cs-module.html

42 lines
1.4 KiB
HTML
Raw Permalink Normal View History

{{/*
This template is used to render a Client-Server API Module. Modules are defined
alongside the `_index.md` for the CS API.
The following parameters are expected:
* `filename` the name of the module file to render, without extension (i.e. `spaces`).
* `name` the display name of the module (i.e. `Spaces`).
*/}}
{{ $name := .Params.name }}
{{ $filename := .Params.filename }}
{{ with .Site.GetPage "client-server-api/modules" }}
{{ with .Resources.GetMatch (printf "%s%s" $filename ".md") }}
{{/* Preserve previous scratch values so nested modules don't leak */}}
{{ $prevPage := .Scratch.Get "endpoint_page" }}
{{ $prevModule := .Scratch.Get "endpoint_module" }}
{{/* Allow endpoints rendered in the module to accumulate on the parent page */}}
{{ .Scratch.Set "endpoint_page" $.Page }}
{{/* Name the module for grouping in the endpoints list */}}
{{ .Scratch.Set "endpoint_module" $name }}
{{ .RenderShortcodes }}
{{/* Restore previous scratch values */}}
{{ if $prevPage }}
{{ .Scratch.Set "endpoint_page" $prevPage }}
{{ else }}
{{ .Scratch.Delete "endpoint_page" }}
{{ end }}
{{ if $prevModule }}
{{ .Scratch.Set "endpoint_module" $prevModule }}
{{ else }}
{{ .Scratch.Delete "endpoint_module" }}
{{ end }}
{{ end }}
{{ end }}