URL Domain prepending

I’m new to Hugo, so this may be an easy question, but I didn’t see the answer in the docs or forum…honestly, I’m hoping it is easy and I’m just missing something. :slight_smile:

The forum is saying new users can have two links per post, but this is a URL problem. In this post, I’ve substituted “h:” for “https:” so it will let me post.

I’ve defined a variable in my content like so

refs: [“h://www.amazon.com”,“h://www.ciscopress.com”,“h://www.linkedin.com”]
and my baseURL in config.toml is baseURL = “h://www.nextpertise.net/”

and then want to reference it in my single.html template:

{{ if .Params.refs }}References:
{{range .Params.refs}}&nbsp&nbsp{{ . }}
{{end}}{{end}}

The output text is right, but the URL being referenced is prepending my baseURL like this: “h://www.nextpertise.net/https://www.amazon.com”. What am I doing wrong?

Unable to reproduce based on your description.

Please post a link to the public repository for your site. See:
https://discourse.gohugo.io/t/requesting-help/9132

Include a link to the source code repository of your project, because we really need the context of seeing your templates and partials to be able to help you. It is trivial to do a quick git clone on your repo, then run hugo server in your project, to help you out. On the other hand, recreating your code from screenshots, or sort of guessing at it, is not.

If you can’t share your repository for whatever reason, consider creating a dummy repo that you can share, which reproduces the problem you’re experiencing.

Also, when sharing URLs that don’t need to be linked, share them as “code”.

https://example.org :sunglasses:

1 Like

Thanks guys for the help! Joe, my site can be viewed at nextpertise.net and the repo is at

https://github.com/brentstewart/nextpertise

Also, the original code causing the problem was:

{{ if .Params.refs }}References: {{range .Params.refs}}&nbsp&nbsp <a href="{{ . | urlize }}">{{ . }} </a>{{end}}{{end}}

I think some of the html was interpreted and not displayed in the original post.
Thanks for the tip Maiki!

  1. When sharing code in the forums, use code fences not blockquotes. See https://discourse.gohugo.io/t/sharing-code-in-the-forums/8968.
  2. The code displayed in your original post does not match the code in your repository. See #1.
  3. You should run your final HTML through a validator such as https://validator.w3.org/. You’ve got some issues.
  4. The urlize function does not do what you think it does. In this case, its misuse caused your problem. Do this instead:
<div style="color:grey; font-size:16px;">
  {{ if .Params.refs }}
    <strong>References:</strong><br>
    {{ range .Params.refs }}
      &nbsp;&nbsp;<a href="{{ . }}">{{ . }}</a><br>
    {{ end }}
  {{ end }}
</div>
1 Like

Thank you so much! That fixes the issue. I appreciate your other feedback as well!

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.