Get the 1st word from front matter with more than 1 word

Continuing the discussion from Get a substr of a string using length of words instead of characters (SOLVED):

How do I display just Cyndi in my single.html file when Cyndi Lauper is declared in the front matter? Note that I have multiple people in the section with names that vary in length so I need to find the first white space and remove it and everything thereafter to cater for everyone.

Can countwords be used where you where you somehow then return only the first word? I’ve seen the string and split and substr functions in the Hugo Docs but I’m not sure how to apply them. And the solution I found in the forum might/might-not work for my use case.

/content/people/cyndilauper.md

+++
Name = "Cyndi Lauper "
+++

/layouts/people/single.html

"follow Cyndi on Twitter'

Hmm, wild guess: maybe using index after using split? Search for this:

 {{ $section := index (split .URL "/") 1 }}

… on this post:

I appreciate the link @RickCogley but that’s confusing for me.

{{ with .Params.name }}
{{ index (split . " ") 0 }}
{{ end }}
3 Likes

That’s so awesome, so handy, and so powerful. Thanks @rdwatters.

1 Like