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:


apple = ""
pineapple = ""

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


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

replaced by:

<a href="">Go to store now</a>
<a href="">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:


<a href="{{ }}">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 (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.