Phlow
#1
I have variables/strings in the following format with the variable name Zeitraum_Begin
2019-05-01
I want to remove the last six characters to show only the year.
2019
I use {{ .Zeitraum_Begin | truncate 4 }}
But it put out 2019 …
which is correct.
Is there a filter to remove x characters from a string? I haven’t found a filter for that.
bep
#2
If you store them in your data files/front matter without quotes, you could use date formatting to get to where you want.
If it’s a string, see https://gohugo.io/functions/substr/#readout
Phlow
#3
Hey @bep thank you for your answer! So there is no truncate version without the …, right?
I will try the date-version. Thank you for the link!
Phlow
#4
It would be a good idea to link the https://gohugo.io/functions/substr/ page on https://gohugo.io/functions/truncate/ › That’s where I searched first for a similiar function!
system
closed
#5
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.