gora
October 21, 2023, 10:44am
1
Hi there,
In my page frontmatter I add values such as
# if the value is 1 in the page layout I show it as 1 km
1
# if the value is 0.25 I currently show it as 0.25 km
0.25
is it posible to tell Hugo to display 0.25 km as 250 meters by default the same way it turn 1 to 1st etc?
Thanks
Nope. (The 1 => 1st mapping is quite useless if your site is not in English). And the relation between 0.25/250 is far less obvious than that between 1/1st. How would anyone know if/when you want kilometers displayed as meters? Not even booking.com bothers with this kind of conversion, they display all distances as 0.x km
(from center or whatever).
1 Like
gora
October 21, 2023, 11:00am
3
Ok
So something like this is my only option
{{ with .Params.distance }}
{{ if ge . 1.0 }}
{{ printf "%d km" . }}
{{ else }}
{{ printf "%d meters" (mul . 1000) }}
{{ end }}
{{ end }}
but then I am not able to figure out how to use the i18n “km” instead of the simple km text.
any solution on this? thanks
gora
October 22, 2023, 10:10am
4
The above code didnt work for me so I instead use this code:
{{ with .Params.distance }}
{{ if ge . 1 }}
{{ . }} {{ i18n "km" }}
{{ else }}
{{ mul . 1000 }} {{ i18n "meters" }}
{{ end }}
{{ end }}
Hope this helped someone.
Thanks!
system
Closed
October 24, 2023, 10:10am
5
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.