I have a simple range : {{ range where .Site.RegularPages "Section" "evenements" }}
What I want to do is “if there are not results, do this”
{{ range where .Site.RegularPages "Section" "evenements" }}
{{ if results > 0}}
{{ .Title}}
{{ .Content}}
{{ .Permalink}}
{{else}}
no events yet, come back soon
{{ $events := where .Site.RegularPages "Section" "evenements" }}
{{ if len $events | gt 1 }}
// do the ranging
{{ else }}
no events yet, come back soon
{{ end }}
By default Hugo is using Go’s template engine. In the docs you can find a guide that explains the basics of it.
Go’s html/template package is an extensions of the text/html package which provides a small set of common template functions. You don’t have to understand Go, it’s just a background info.
Hugo extends the set of common template functions to fill the toolbelt for a static site generator. Here is a list of those functions.
Exactly. It doesn’t seem to be hard
Well, the text/html package named this function len. Here’s an overview all functions provided by text/template. As I said Hugo just adds a bunch of other useful template functions that you can find here.
The | operator is similar to the Unix pipe. It basically pipes the output of the previous function as input to the next function. This allows you to chain multiple operations elegantly. However, I would refer again to the Go template primer.
Btw, @rdwatters started to rewrite the documentation. Please let us know were exactly you got stuck and what can be improved. We try to incorporate the feedback from new users.
where gives you a list of all pages (which are somewhat similar to objects in JS). Such a list can be assigned to a variable as you already know it. where also allows even some more fine grained filtering for which you can find examples in the docs.
This way you print the internal representation of the pages list.
I’m not quite sure but I guess you only have a single event. Nonetheless, since you have a list assigned to $events you can range over it like in JS with range.
Pages aren’t really objects in the way that you can’t call methods with the dot notation. Instead you pass the “object” as an argument to a function, e.g. len $events.
https://gohugo.io are the official docs. https://hugodocs.info used to be the rewritten version by @rdwatters. I linked both because the latter one is basically a revamped version. Don’t be confused. I just linked both so that you get the best of both worlds.
Yes. We’re also planning a redesign of the website made by @budparr. Once the design is done we’ll merge the content and put them on www.gohugo.io. Stay tuned!
Sometimes it takes a bit of time and some pointers to grasp new tools.
Thanks. I’m just watching the forum while doing other stuff. The Hugo community is rather small but we try our best to help. A 10 min deadline is hard to keep, so don’t set your expectations too high