SOLVED: How to stop newline after shortcode output?

I have a VERY simply shortcode, “productname.html”, that refers to a config parameter:


When I write content containing “{{<productname>}}'s the best” the rendered HTML includes a trailing newline, which results in unwanted whitespace before my apostrophe. eg: Super Product 's the best

I have a work-around, but it’s very silly. I extend the shortcut so that it understands parameters,

{{.Site.Params.productname}}{{ if .Get 0}}{{index .Params 0}}{{ end }}

… and now I can write content like: “{{<productname> "'s"}} the best

Is there any way around this? Alternatively, is there a smarter way to make config parameters appear in content?

Thank you!

1 Like

Thank you for the pointer. I’m not sure this is expected behaviour, given practically every text editor on earth puts an EOL marker of some kind at the end of a line, but that’s fine. I can work around it.

I’m really enjoying getting to know Hugo.

Try the -}} syntax as template enddelimiter

Tantalising! Sadly, my search skills apparently are not up to the task. I can’t find any reference to defining a template enddelimiter (or end delimiter!)

Found it here – and it works!

ie: My simple shortcode, “productname.html”, that refers to a config parameter now looks like this:

{{- .Site.Params.productname -}}


Perhaps you have any suggestion on how to fix my new line problem. Here is my shortcode:

{{if in .Page.Permalink “xap97”}}{{“”}}
{{else if in .Page.Permalink “xap100”}}{{“”}}
{{else if in .Page.Permalink “xap101”}}{{“”}}
{{else if in .Page.Permalink “xap102”}}{{“”}}
{{else if in .Page.Permalink “xap110”}}{{“”}}
{{else if in .Page.Permalink “xap120”}}{{“”}}

If its the last case, then there is no newline generated, all other cases produce a newline.
If I put the entire statement on one line it does not produce any newlines.
In order to maintain my code I would like to keep it in the above form.

Any help would be greatly appreciated

I haven’t tested it, and am no Hugo expert, but I don’t see any evidence that you have tried the -}} syntax as discussed in this topic. Maybe give that a go :slight_smile:

1 Like