How to display informations from a shortcode

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 :smiley:

I have continued my investigation (the repository is updated) and now I can retrieve information from a shortcode (only if the call is after the shortcode). Here the call.html shortcode (I renamed it):

{{ $value := .Get "identifier" }}
{{ range site.RegularPages.ByTitle }}
  {{ range .Store.GetSortedMapValues "definition" }}
  {{ if eq .id $value }}<span id="{{ .id }}">(<em>definition</em>: {{ .content | markdownify }})</span>{{ end }}
  {{ end }}
{{ end }}

And its use:

And we already know what is a book{{< call identifier="book" >}}.

Now my question is: is it a way to display an information from a shortcode when the shortcode is after the call? Something like that:

About the page{{< call identifier="page" >}}.

{{< definition type="definition" id="page" name="The Page" >}}
A page is a piece of a book.
{{< /definition >}}