After a first step (Extract data from shortcodes inside another page) (a huge thanks to @jmooring for that), I try to display informations from a shortcode in a page.
What I’m attempting to do:
- inside various pages, markup some text (with few parameters), for example a definition, with a first shortcode,
definition.html
- display the content and the parameters inside in pages (sometimes the same as the previous step), with a second shortcode
definition-call.html
I made a small prototype for explaining that:
- repo: https://github.com/antoinentl/hugo-call-me-back
- content organization: the chapters pages display content files from a section (
chapters
) and subsections (01
,02
). It’s like a book structure - first shortcode:
definition.html
markup a text with parameters, and store the data (content and parameters)
{{ $mainId := .Get "id" }}
{{ $name := .Get "name" }}
{{ with $captureName := .Get "type" }}
{{ with $.Inner }}
{{ $id := printf "%d" $.Ordinal }}
{{ $gent := dict "name" $name "id" $mainId "content" (string .) }}
{{ $.Page.Store.SetInMap $captureName $id $gent }}
{{ end }}
{{ end }}
<p class="definition">{{ .Inner | markdownify }}</p>
- second shortcode:
definition-call.html
aims to display few informations from the first shortcode
{{ $valeur := .Get 0 }}
{{ range site.RegularPages.ByTitle }}
{{ range .Store.GetSortedMapValues $valeur }}
<span id="{{ .id }}">(<em>definition</em>: {{ .content | markdownify }})</span>
{{ end }}
{{ end }}
- I can retrieve all the definitions with this code (actually on the home page):
{{ range site.RegularPages.ByTitle }}
{{ $noop := .WordCount }}
{{ if .HasShortcode "definition" }}
{{ range .Store.GetSortedMapValues "definition" }}
<li id="{{ .id }}"><strong>{{ .name }}</strong>: {{ .content | markdownify }}</li>
{{ end }}
{{ end }}
{{ end }}
I’m able to produce a page which list all the definitions (thanks to the help of @jmooring), on the home page, but I can’t retrieve data from a shortcode inside a page.
Any help is welcome