Given shortcode parameter, get its value defined in config.toml

Hi all, I’m creating a shortcode trying to get the variable value whose name is defined in the shortcode parameter. Take a example:

/config.toml:

...
[params.store]
apple = "http://www.apple.com/"
pineapple = "http://www.pineapple.com/"
...

The shortcode I want would translate the anchor into the corresponding target link, like:

/content/sample.md:

{{< store apple >}}
{{< store pineapple >}}

replaced by:

<a href="http://www.apple.com/">Go to store now</a>
<a href="http://www.pineapple.com/">Go to store now</a>

I don’t want use if statement to determine parameter names then get the corresponding target store link. I’d like to get value directly by parameter like:

/layout/shortcodes/store.html:

<a href="{{ .Site.Params.store.PARAMETER0 }}">Go to store now</a>

Is there any way to accomplish this? Thanks for any tips.:slight_smile:

Give this snippet a try:

<a href="{{  index .Site.Params.store (index .Params 0) }}">Go to store now</a>

However, I would always check if a parameter was passed to the shortcode and you should make sure that apple exists as keyword in your config file. Otherwise, Hugo will “fail” silently and replace the expected url with an empty string.