Hi there I have a set of front matter variables defined in each article.
I would like to make a url out of the same which i can pass it to some thirdparty library
lets say i have a front matter like this
+++
name=mike
age=24
height=167
+++
i would like to generate this into a variable in hugo template (single)
?name=mike&age=24&height=167
In order to do this i tried various things like
{{ $someVar := "" }}
{{ range $index, $component := .Params }}
{{ $someVar := (print $someVar $index "=" $component "&") }}
{{ end }}
The problem is that $someVar is only available within the loop. Outside the loop its empty.
Kindly help.
zwbetz
July 11, 2019, 9:49pm
2
Hi there. When inside the loop use =
instead of :=
1 Like
Hi thanks for the reply,
It worked like a charm
I have one problem though
If i print the variable like this
{{ $somVar }} i get the expected output βname=mike&age=24&height=167β
but if i put the same as a parameter to a url like
link rel=βhttps://chatbot.hellotars.com/conv/rkoHZD/?{ { $url }}β
it generates the value as
https://chatbot.hellotars.com/conv/rkoHZD/?name%3Dmike%26age%3D24%26height%3D167
I have done something thats not right
zwbetz
July 11, 2019, 10:08pm
5
Also, since you are joining each param on &
, I would create an empty slice, then append the key=value
on each loop, then use the delimit function for &
. Merely personal preference though.
1 Like
I cant thank you enough
All my issues are solved.
Thank You very much
1 Like