Rendering the output of Functions

I’m confused and would be grateful for guidance on using Functions within a page, in this case, my About page. Here’s what I’m trying to do in my About page:

### Other Stuff
- Astrological Sign: 
{{ $slice := slice "Aries" "Taurus" "Gemini" "Cancer" "Leo" "Virgo" "Libra" "Scorpio" "Sagittarius" "Capricorn" "Aquarius" "Pisces" }}
{{ $shuffled := shuffle $slice }}
{{ $random := index $shuffled 0 }}
{{ $random }}
- Big Five
	- Extroversion: {{ math.Rand | mul 99 | math.Floor }}
	- Emotional Stability: {{ math.Rand | mul 99 | math.Floor }}
	- Agreeableness: {{ math.Rand | mul 99 | math.Floor }}
	- Conscientiousness: {{ math.Rand | mul 99 | math.Floor }}
	- Openness to Experience: {{ math.Rand | mul 99 | math.Floor }}
- Enneagram Number: {{ math.Rand | mul 9 | math.Floor }}

This renders in the HTML output as

<h3 id="other-stuff">Other Stuff</h3>
<ul>
<li>Astrological Sign:
{{ $slice := slice &ldquo;Aries&rdquo; &ldquo;Taurus&rdquo; &ldquo;Gemini&rdquo; &ldquo;Cancer&rdquo; &ldquo;Leo&rdquo; &ldquo;Virgo&rdquo; &ldquo;Libra&rdquo; &ldquo;Scorpio&rdquo; &ldquo;Sagittarius&rdquo; &ldquo;Capricorn&rdquo; &ldquo;Aquarius&rdquo; &ldquo;Pisces&rdquo; }}
{{ $shuffled := shuffle $slice }}
{{ $random := index $shuffled 0 }}
{{ $random }}</li>
<li>Big Five
<ul>
<li>Extroversion: {{ math.Rand | mul 99 | math.Floor }}</li>
<li>Emotional Stability: {{ math.Rand | mul 99 | math.Floor }}</li>
<li>Agreeableness: {{ math.Rand | mul 99 | math.Floor }}</li>
<li>Conscientiousness: {{ math.Rand | mul 99 | math.Floor }}</li>
<li>Openness to Experience: {{ math.Rand | mul 99 | math.Floor }}</li>
</ul>
</li>
<li>Enneagram Number: {{ math.Rand | mul 9 | math.Floor }}</li>
</ul>

Here are the relevant portions of my config.toml

enableInlineShortcodes = true
pygmentsCodeFences = true
pygmentsUseClasses = true

[markup.goldmark.renderer]
  # Allow HTML in Markdown
    unsafe = true

and my hugo env

hugo v0.134.2+extended darwin/arm64 BuildDate=2024-09-10T10:46:33Z VendorInfo=brew
GOOS="darwin"
GOARCH="arm64"
GOVERSION="go1.23.1"
github.com/sass/libsass="3.6.6"
github.com/webmproject/libwebp="v1.3.2"

I’m sure I’m missing something obvious in the docs. And yet I’ve combed through all the support documents that I can think to consult, with all the search terms I can come up with on my own, and I’m stumped.

You are using go template code {{}}directly in your markup. That does not work. That can only be used in templates , partials and shortcodes.

you enabled inline shortcodes but you did not define one in your markup

Have a look at the respective doc pages for these four.

So all you wrote is just text.

Thank you for answering so quickly and helpfully. I missed the fact that functions cannot be used directly in markup. I’ll set it up as a shortcode or series of shortcodes.

There’s also

Ah, I see. What I really wanted was an inline shortcode. This section of the documentation explains how to achieve what I was trying to accomplish.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.