ianare
August 9, 2018, 4:46pm
1
<div style="background-image: url('{{ "/img/principal.jpg" | relURL }}');">
outputs:
<div style="background-image: url('/img/principal.jpg');">
But
<img src="{{ "/img/icon-form.png" | relURL }}">
Outputs:
<img src="../../img/icon-form.png">
The image is correct, the inline style is not.
config.yaml:
relativeURLs: true
canonifyURLs: false
uglyurls: false
Why is this happening?
Thank you!
maiki
August 9, 2018, 5:18pm
2
More information is needed to troubleshoot your issue. Please read Requesting Help and update your post.
ianare
August 10, 2018, 8:40am
3
I’m running this on version 0.46
The weird thing is I’m getting this difference in behavior on the same partial.
This is a custom theme, but unfortunately I can’t really share it (intranet site).
Can you at least confirm that this is not the normal behavior? Meaning that the relURL output should have the same root.
Thanks
Is your Hugo site published in a sub-directory of the intranet?
ianare
August 24, 2018, 11:46am
5
Yes it’s in a subdirectory, but what’s strange is that the relURL output is different for two different things on the same page .
In Hugo relURL
is relative to the root of a project. Since your site is published in a sub-directory of the intranet Hugo cannot find that asset.
I recommend that you remove the following settings from your config
relativeURLs: true
canonifyURLs: false
The above settings are doing opposite things. There is no need to have them.
Whenever you create a link to an asset in your templates do it like so:
<img src="{{ "img/icon-form.png" | absURL }}">
Also take care not to use a forward slash ‘/’ in the beginning of these links.
Whenever a link begins with a forward slash Hugo turns it into a relative link and absURL
has no effect.
Please do the above and let me know if this fixed the issue.
ianare
August 24, 2018, 12:51pm
7
The production site is on its own domain, and it does work as expected there with
relativeURLs: false
The pre-production is in a subdirectory and I can’t really do anything about that so that’s not a solution for me.
I still don’t understand why relURL
behaves differently depending on the HTML tag in which it’s placed.
In the original snippet you’ll notice that both assets are in the same exact directory. Why would one be found and not the other?
Thanks
ianare:
I still don’t understand why relURL
behaves differently depending on the HTML tag in which it’s placed.
In the original snippet you’ll notice that both assets are in the same exact directory. Why would one be found and not the other?
It’s difficult to say without seeing the project.
I would guess that since you call that image as an inline style the context is different.
However I am not familiar with all the intricacies of the go-html package.
That is a question for the Dev team
CC / @bep @moorereason