Hello,
I’m sure there is the answer somewhere but I keep struggling. I want to generate this Url in my template (an edit link):
https://github.dev/mat/website/blob/main/content/_index.md
After many tries, I’ve came up with that:
{{ path.Join .Site.Params.editUrl .File.Path }}
It works but it removes a slash in .Site.Params.editUrl
.
https://github.dev
become https:/github.dev
So my url is missing a slash to work properly:
https:/github.dev/mat/website/blob/main/content/_index.md
I probably don’t use the right function, but I always ended up with not the good url whatever I tried.
Thanks for your help !
frjo
April 14, 2023, 11:37am
2
Replace path.Join
with add
to make it handle schemas like “https://”.
You need to take care of slash at start and end of the strings when using add
. It will not like path.Join
handle that for you.
Thank you very much both for your answers.
This is my code now and it works:
{{/* .File.Path has a backslash from windows, this transform it into a normal slash */}}
{{ $cleanUrl := path.Join .File.Path }}
{{ $editUrl := add .Site.Params.editUrl $cleanUrl }}
1 Like
system
Closed
April 17, 2023, 2:50pm
5
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.