The default template functions are quite limited. Doing some quick websearches, there are some alternatives:
But how do I use them with Hugo?
PS: My current problem is that I need findRE
but for literal strings.
I am afraid that you cannot use alternative template engines with Hugo.
We had a discussion about literal and interpreted strings in Go templates a few days ago in this topic:
I have found that it is always best to wrap strings in backticks instead of double quotes in Go templates.
Strings wrapped in backticks are literal.
Strings wrapped in double quotes are interpreted.
This way one avoids problems like the one you encountered.
Therefore the Go comment in your template should read:
{{ `<!-- Hero Area Image d'accueil -->` | safeHTML }}
For an explanation have a look at the Go spec: String Literals
Try my suggestions from that other post and see if they help you.
1 Like
My problem is not with go strings, I need to do
{{ $re := ($.File.BaseFileName | regexp.QuoteMeta) }}
But how do I import the library in the templates?
import (
"regexp"
)
There is no plugin system in Hugo. You cannot import external Go packages.
We only have the replaceRE
and findRE
functions for Regular Expressions.
Wouldn’t it be a good idea to import some of the standard libraries then? E.g., regexp
is very useful. Importing the standard libraries doesn’t have much overhead either, no?
The functions I mentioned above already make use of the Go regex package.
Please have a look at the doc:
1 Like