Conditional checks not working in href attribute of anchor tag in shortcodes

Please check this issue for details

I think it’s a bug and need to be fixed for this case

Please don’t expect people to navigate to some other site to find the information to help you. Copy-and-pasting that info isn’t too much to ask.

Am able to reproduce this, with the below error

Error: Error building site: “C:\Hugo\Sites\condShortcodeHref\”: failed to render shortcode “redirection-url”: failed to process shortcode: “C:\Hugo\Sites\condShortcodeHref\layouts\shortcodes\redirection-url.html:1:75”: execute of template failed: html/template:shortcodes/redirection-url.html:1:75: {{index .Params 0}} appears in an ambiguous context within a URL

The fix is to add a leading slash to the href.

Also this can be written more concisely using with and .Get

<a href="/{{with $}}{{.}}/{{end}}{{.Get 0}}">Click here</a>

@bep Apologies for that. @zwbetz Thanks for the answer. I can now make that work by adding a leading slash to the href.

1 Like