Issue with shortcode param lengths

I’m working on a shortcode and I want a value to be based on the length of the parameter set for the shortcode. In short, I want the word to be either the first parameter if there’s only one parameter or the second parameter if there are two parameters. Like this:

<!-- layouts/shortcodes/word.html -->
{{- $term := cond (eq (len .Params) 2) (.Get 1) (.Get 0) -}}

And then here’s an example usage:

{{< word "one" >}}          <!-- should output "one" -->
{{< word "one" "two" >}} <!-- should output "two" -->

The problem is that it doesn’t work if there’s only one parameter. In that case I get No shortcode param at .Get 1 in the error output. It seems to me that the .Get 1 is being evaluated even if the condition fails.

Has anyone else run into this?

@cmal had recently posted a workaround for that limitation:

@kaushalmodi I just saw that others had posted this same question. Didn’t do my homework ahead of time. Egg on my face! :slight_smile: Thanks!